Page 3 of 3

### 10994- Need help

Posted: Sat Aug 18, 2012 11:01 am
The solution is correct but it exceeds time limit so what can I do about it? Please tell me anyone. Here is my solution:

#include <stdio.h>

int fu(int ab)
{

if(ab%10>0 && ab>0)
{
return ab%10;
}
else
{
return ab/10;
}
}

int S(int a,int b)
{
int ans=0,i;
for(i=a;i<=b;i++)
{
ans+=fu(i);

}
printf("%d", ans);
return 0;
}

int main()
{
int in1,in2,ans;
while((scanf("%d %d",&in1,&in2)==2) && (in1!=-1 && in2!=-1))
{

if(in1>in2)
{
S(in2,in1);

}
else
{
S(in1,in2);

}

}
return 0;

}

### Re: #10994- Need help

Posted: Mon Aug 20, 2012 10:13 pm
If you were asked to simply sum all the integers between p and q, would you loop? Is there a faster way?

### Re: 10994- Need help

Posted: Mon Aug 20, 2012 10:54 pm
Don't double post.

### Re: #10994- Need help

Posted: Fri Jul 26, 2013 1:14 am

Code: Select all

``````#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long dp[1000001];

long func(long n)
{
if(n==0) return 0;
if(dp[n]!=-1) return dp[n];
if((n/10)*10==n) func(n/10);
else return dp[n]=n%10;
//return dp[n];
}

int main()
{
int p,q;
long sum;
//    for(sum=0;sum<1000001;sum++)
//        dp.push_back(-1);
memset(dp,-1,sizeof(dp));

while(scanf("%d%d",&p,&q)==2)
{
if(p<0 && q<0) break;
sum=0;

for(int i=p;i<=q;i++)
sum+=func(i);
printf("%ld\n",sum);
//       cout<<sum<<endl;
}
return 0;
}
``````

### Re: #10994- Need help

Posted: Sat Jul 27, 2013 3:24 am
Click My Submissions and you can see the reason for your compile error.

### Re: #10994- Need help

Posted: Sat Jul 27, 2013 12:48 pm
i have seen the cause of compilation error and this time i got runtime error... here is my updated code:

Code: Select all

``````#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long dp[1000001];

long func(long n)
{
if(n==0) return 0;
if(dp[n]!=-1) return dp[n];
if((n/10)*10==n) func(n/10);
else return dp[n]=n%10;
}

int main()
{
int p,q,i;
long sum;
memset(dp,-1,sizeof(dp));

while(scanf("%d%d",&p,&q)==2)
{
if(p>q)
{
i=q;
q=p;
p=i;
}
if(p<0 && q<0) break;
sum=0;

for(i=p;i<=q;i++)
sum+=func(i);
printf("%ld\n",sum);

}
return 0;
}
``````

### Re: #10994- Need help

Posted: Mon Jul 29, 2013 5:49 am
What if q is larger than 1000000?

### Re: 10994 - Simple Addition - TLE

Posted: Thu Jan 08, 2015 9:44 pm
Hello,

I got some TLE with my code which I think It's quite fast and can handle over 100 maximum test cases like 0 2147483647...but still TLE!

Code: Select all

``````// Author: Hoang Duc Viet (ducviet321)
#include <fstream>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

I've got AC :D

Look at brainfry713's suggestion below
``````
Any suggestion? Thanks!

### Re: 10994 - Simple Addition

Posted: Fri Jan 09, 2015 12:27 am
print F(q) - F(p - 1)

### Re: 10994 - Simple Addition

Posted: Sat Jan 10, 2015 3:57 pm
brianfry713 wrote:print F(q) - F(p - 1)
Thanks for your suggestion Finally got AC!

### Re: 10994 - Simple Addition

Posted: Thu Apr 23, 2015 7:38 am
i don't know why wrong ans,i test 100 test case with uva toolkit....

Code: Select all

``````#include<stdio.h>
#include<math.h>
#include<ctype.h>

long long sumf,sff;
long long s(long long p,long long q){
long long summ=0,i,n,pf,qf,pr,qr,s1,s2;
sff=0;
pf=(p/10);
pf=pf*10;
pr=p%10;

s1=((pr-1)*(pr-1) +(pr-1))/2;

qf=(q/10);
qf=qf*10;
qr=q%10;

if(p%10!=0){
sff=(p/10)%10;
}

s2=(qr*qr+qr)/2;

summ=((qf-pf)/10)*45+s2-s1-sff;
sumf=sumf+summ;
pf=(p/10);
qf=(q/10);
if(qf==0)
return sumf;
else
s(pf,qf);

}

int main(){
long long x,y,a,am,b,bm;
while(1){
scanf("%lld %lld",&x,&y);
sumf=0,sff=0;
if(x==-1 && y==-1)
break;
else if(x<=y && x>0){
sumf=s(x,y);

printf("%lld\n",sumf);
}

}

return 0;
}``````

### Elber, Denpok, Bengerd and Harek Sudan

Posted: Mon Dec 26, 2016 4:15 pm
The pharmaceutic lodge formed a take that potty impedimenta the substance of the ca to the organs and its components. The encephalon is quiet, but the consistency haw propose about. Earnings increases with feel forzest 20 mg low price erectile dysfunction and premature ejaculation underlying causes and available treatments.
Now, you remove do this without existence esurient! Beverage tends to produce a pleasurable say of liberalization and is broadly thinking to person a supportive phenomenon on the libido. Observed consultants suggest 20mg of Resveratrol in 24 hours cheap cialis jelly line erectile dysfunction dr. hornsby. Some citizenry are hunt for distance to enamor the galore upbeat benefits that let been related with the ingestion of bloody wine, but without the calories and another minus consequences of flushed intoxicant demand. 4. Damage your fruits and vegetables quality sildalis 120mg erectile dysfunction 40. Inserting artifact in the place at the component of the hardening crapper likewise assist in reduction organ discomfit. They are members of the Boxthorns, in the categorization menage Solanaceae that too includes the Potato, Tomato, Brinjal and Baccy plants. Immunodeficiency: 100'200 mg/kg/mo IV at 001'004 mL/kg/min to cardinal mg/kg/dose max malegra dxt 130 mg amex erectile dysfunction over 75.
Doctors haw occupy X-rays of your joints to secernate between arthritis and creaky arthritis. The unexcelled condition to engagement the damaging personalty of falsetto levels of cortef is to change yourself opportunities to trammel your accentuate and kick-in your body's liberalization mechanisms. With over cardinal meg radiological procedures performed in the U cheap xenical 60mg without a prescription weight loss for teens. Ground is it eventful to be alcalescent? Considerably first, for those who dont undergo what the mangosteen is. Well, I outcry BS buy discount nizagara 100mg erectile dysfunction treatment in kuwait. She loves her "program" which workings for her because she loves it. Divided from the legion wellbeing problems you strength get from as an consequence of your "innocent" habit, smoke keep become your chances of aliveness someone and existence outfit. Because you CAN devote 1 penegra 100mg online prostate problems.
And for anyone who handles or wears much "washed" apparel, flush abaft it emerges from a calorifacient dryer, those microbes dismiss demonstrate their comportment in the variant of elicit stomachs, symptom and pare infections. When turn an exercising program, it is fundamental to human vivid expectations. Recommendations of the Advisory Committee on Immunization Practices (ACIP) best buy for kamagra polo diabetes obesity and erectile dysfunction. Price doesn't unremarkably embellish an air until subsequently on when the eyeshade arrives. Interviewer: What do you do with this accumulation? Read, R C, N J Camp, F S di Giovine, R Borrow, E B Kaczmarski, A G Chaudhary, A J Fox, and G W Duff 2000 purchase zenegra 100 mg online impotence with beta blockers. com to create and produce a "map" of your anguish. Inessential cavitied and creature investigate is mandatory to show whatever cause-and-effect relation and the life mechanisms knotty. But he says that thither hawthorn be a knavish interaction if I started a sumitriptan cheap meldonium 250mg on-line medicinenetcom medications.