Page 2 of 3

Posted: Sat Apr 01, 2006 4:10 pm
by Ankur Jaiswal
i got a direct formula for the second grp numbers (i.e the numbers not ending in 0) but i am not able to get the formula for the numbers ending in 0...So, i got TLE.
my output is correct.
i am using following code for the numbers ending in 0 -

Code: Select all

for(i=temp;i<=q;i+=10){
                        p=i;
                        while(p%10==0)
                                p/=10;
                        ans+=p%10;
                }

Posted: Sun Apr 09, 2006 5:42 pm
by sakhassan
U can modify the formula as follows:

function()
{

............
............
while(n)
{
m = n%10;
n = n/10;
s1 += ( ( m * (m+1) ) / 2 );
s2 += (double)n * 45;

}


return (s1 + s2);

}
-------------------------------------
When u call the function

just
if(p)
sum = function(q)-function(p-1)
else
sum = function(q)


Hope TLE will mitigate..... this time :wink:

Posted: Wed May 03, 2006 11:44 am
by Ankur Jaiswal
Thanx a lot for providing such a simple alternative but now i am getting WA :(

Posted: Sat Aug 05, 2006 7:07 am
by Martin Macko
Ankur Jaiswal wrote:Thanx a lot for providing such a simple alternative but now i am getting WA :(
Try these test cases:

Code: Select all

0 0
0 1
0 2
0 3
1 1
1 2
1 3
2 2
2 3
3 3
0 2147483647
4868141 2147483647
2147483646 2147483647
2147483647 2147483647
0 1697831704
1 1697831704
5874571 5874571
8547855 8547856
100580521 1989930148
155996425 1206496545
147550223 1536716708
707325775 1340801806
1040075891 1420810599
1714064943 1984493018
686413674 1329025269
736919653 1524063966
71724731 579366154
166786016 735362579
1002657859 1541865667
784743773 2037402352
-7 -7
My AC's output:

Code: Select all

0
1
3
6
1
3
6
2
5
3
10737418158
10713077499
13
7
8489158466
8489158466
1
11
9446748140
5252500596
6945832429
3167380180
1903673541
1352140396
3213057997
3935721558
2538207103
2842882808
2696039024
6263292902

Posted: Sat Oct 07, 2006 3:21 pm
by Spykaj
Thanks, good tests ;] i have acc.

Why CE????

Posted: Wed Jun 27, 2007 8:41 am
by kintu
/* Remove Whole Messege as no help come */

Re: Why CE????

Posted: Wed Jun 27, 2007 12:42 pm
by little joey
kintu wrote: But what hell happen to Online Judge.
Well, not very much lately...

About your problem: untyped numeric constants, consisting of digits only, are translated by the compiler in to integers, which have a range [-2^31..2^31>. The number 4.5 billion is outside this range, so it issues an error.

Add a type to the constant by using the proper suffix, and it will be fine. "4500000000ll" will do.

Posted: Wed Jun 27, 2007 2:45 pm
by kintu
well, as i know befire that long long type integer have a range= 2^64
Which is in the range of 4.5billion
So, what type problem has occured here, i can't understand.
And by-
Add a type to the constant by using the proper suffix, and it will be fine. "4500000000ll" will do.
what you want to do, i can't understand. Please can you explain where to modify my code???

Posted: Thu Jun 28, 2007 12:23 pm
by annhy
Martin Macko wrote:Try these test cases:

Code: Select all

0 0
0 1
0 2
0 3
1 1
1 2
1 3
2 2
2 3
3 3
0 2147483647
4868141 2147483647
2147483646 2147483647
2147483647 2147483647
0 1697831704
1 1697831704
5874571 5874571
8547855 8547856
100580521 1989930148
155996425 1206496545
147550223 1536716708
707325775 1340801806
1040075891 1420810599
1714064943 1984493018
686413674 1329025269
736919653 1524063966
71724731 579366154
166786016 735362579
1002657859 1541865667
784743773 2037402352
-7 -7
My AC's output:

Code: Select all

0
1
3
6
1
3
6
2
5
3
10737418158
10713077499
13
7
8489158466
8489158466
1
11
9446748140
5252500596
6945832429
3167380180
1903673541
1352140396
3213057997
3935721558
2538207103
2842882808
2696039024
6263292902
Thanks Macko, I got AC. :D

For someone still getting WA: note the overflowing cases!!

Re: 10994 Compile Error

Posted: Wed Sep 01, 2010 8:54 pm
by hosnayen
Can any1 help me ... :( where is my fault.. it seems to be ok.. or give me some critical input..
here is my code... thanks in advance :)

Code: Select all

/*
	Author : Hosnayen Alam Siddiquee.
	University of Science & Technology Chittagong (USTC)
	CSE- 11th Batch
	E-mail: hosnayen_alam@yahoo.com
	Bangladesh	                          Date:	02/08/2010
*/

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>                     // n(n+1)/2
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;

int main(){

 long long p,q;
 long long ans1,ans2;

 while(scanf("%lld%lld",&p,&q)==2){

  if(p < 0 && q < 0) break;

  p=p-1;
  
  ans1=0,ans2=0;

  ans1=(p/10)*45 + (p%10)*(p%10+1)/2  + (p/10)*(p/10+1)/2;

  ans2=(q/10)*45 + (q%10)*(q%10+1)/2  + (q/10)*(q/10+1)/2;


  printf("%lld\n",ans2 - ans1);

   
 }
 return 0;
}

Re: 10994 Compile Error

Posted: Thu Sep 02, 2010 3:13 pm
by sazzadcsedu
Do you think your algorithm is right??.I don't know how did you derive this formula.Your formula
is not correct.try this

Code: Select all

input:
100 123
122 1112
-1 -1

Actual output:
100
4951

your output:
129
10595

And this problem is in volume CIX, not in volume I.So use volume CIX.

Re:

Posted: Wed Mar 16, 2011 12:17 am
by DD
Martin Macko wrote:
Ankur Jaiswal wrote:Thanx a lot for providing such a simple alternative but now i am getting WA :(
Try these test cases:

Code: Select all

0 0
0 1
0 2
0 3
1 1
1 2
1 3
2 2
2 3
3 3
0 2147483647
4868141 2147483647
2147483646 2147483647
2147483647 2147483647
0 1697831704
1 1697831704
5874571 5874571
8547855 8547856
100580521 1989930148
155996425 1206496545
147550223 1536716708
707325775 1340801806
1040075891 1420810599
1714064943 1984493018
686413674 1329025269
736919653 1524063966
71724731 579366154
166786016 735362579
1002657859 1541865667
784743773 2037402352
-7 -7
My AC's output:

Code: Select all

0
1
3
6
1
3
6
2
5
3
10737418158
10713077499
13
7
8489158466
8489158466
1
11
9446748140
5252500596
6945832429
3167380180
1903673541
1352140396
3213057997
3935721558
2538207103
2842882808
2696039024
6263292902
Thanks for your test case, I got some bugs from my program by this.

#10994- Need help

Posted: Fri Aug 17, 2012 9:49 pm
by dotnet12
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: Sat Aug 18, 2012 1:29 am
by brianfry713
Brute force won't work here, you'll need to come up with a faster solution.

Re: #10994- Need help

Posted: Sat Aug 18, 2012 3:10 am
by dotnet12
can u give 1? :D :D