## 10706 - Number Sequence

Moderator: Board moderators

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

### 10706 - Number Sequence

It seems to be easy problem. I got so many wa... Could someone give some test cases?

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
Hi, I can't think of any tricky cases, and random cases aren't very useful here...

Anyway, for i = 2147483647, the output = 2.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
My output of 2147483647 is right.

in:
14
23423
65753
2345
45645756
546454
6786797
131231
78934124
68904565
123487907
5655
778888
101011
546

out:
3
1
5
0
2
5
9
9
2
1
1
5
5
2

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
I get this:
3
1
5
5
2
5
9
7
5
7
1
5
5
2
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
Find out a silly bug and go ac... Thank you for your reply

Minilek
Learning poster
Posts: 90
Joined: Tue Jul 27, 2004 9:34 am
Location: Cambridge, MA
Contact:
[c]
AC
[/c]

Faizur
New poster
Posts: 39
Joined: Fri Jun 06, 2003 3:04 pm

### WA

Hi,
I think the problem is quite an easy one. My problem give correct answers for all the above test cases. But i m still getting WA with this problem.
[c]
#include<stdio.h>
#include<math.h>
void print(double n)
{
double m;
char str[100];
int i;
n++;
if(n<=10)
printf("%.0f",(n-1));
else if(n<=190)
{
n -= 10;
m = ceil(n/2) - 1;
i = n - m*2 - 1;
m += 10;
sprintf(str,"%.0lf",m);
putchar(str);
}
else if(n<=2890)
{
n -= 190;
m = ceil(n/3) - 1;
i = n - m*3 - 1;
m += 100;
sprintf(str,"%.0lf",m);
putchar(str);
}
else if(n<=38890)
{
n -= 2890;
m = ceil(n/4) - 1;
i = n - m*4 - 1;
m += 1000;
sprintf(str,"%.0lf",m);
putchar(str);
}
else if(n<=488890)
{
n -= 38890;
m = ceil(n/5) - 1;
i = n - m*5 - 1;
m += 10000;
sprintf(str,"%.0lf",m);
putchar(str);
}
else if(n<=5888890)
{
n -= 488890;
m = ceil(n/6) - 1;
i = n - m*6 - 1;
m += 100000;
sprintf(str,"%.0lf",m);
putchar(str);
}
else if(n<=68888890)
{
n -= 5888890;
m = ceil(n/7) - 1;
i = n - m*7 - 1;
m += 1000000;
sprintf(str,"%.0lf",m);
putchar(str);
}
else if(n<=788888890)
{
n -= 68888890;
m = ceil(n/8) - 1;
i = n - m*8 - 1;
m += 10000000;
sprintf(str,"%.0lf",m);
putchar(str);
}
putchar('\n');

}
int main()
{
double a,n,t;
long test,i;
double range[10],d=90,digit[10],p,x;
n=0,i=1,t=9;
range[0]=45;
digit[0]=9;
while(i<8)
{
n=range[i-1]+t*d+(((i+1)*d*(d+1))/2.0);
t+=d*(i+1);
digit=t;
range=n;
i++;
d*=10;
}
scanf("%ld",&test);
while(test--)
{
scanf("%lf",&a);
for(i=0;;i++)
if(range>a)
break;
a=a-range[i-1];
d=i+1;
if(!i)
x=0;
else
x=digit[i-1];
p=(2.0*x+d);
p=((sqrt(p*p+8.0*d*a)-p)/(2.0*d));
p=ceil(p)-1;
a-=d*(p*(p+1.0)/2.0)+p*x;
print(a);
}
}
[/c]
Can someone give me some test cases or find out the reson for getting WA.
___________________
Faizur
Cuet Old Sailor

Md. Azam Khan
New poster
Posts: 8
Joined: Tue Jun 15, 2004 7:16 pm
Contact:
Hi Old Sailor (Faizur)!
Your program gives correct answer for all the test cases greater than 45, doesn't it? Seem to me, if u solve "the bug" u will get it accepted. So i m giving u 45 test cases: 1 to 45.

Best regards,
Md. Azam Khan, NewSailor!!!

I born to code

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

### 10706 Why WA???

[cpp]
#include <iostream.h>
#include <math.h>

long long sum(long long n)
{
return n * (n + 1) / 2;
}
int sol(long long x)
{
int i;
for (i = 1;sum(i) < x;i++)
{

}
return x - sum(i - 1);
}

int main()
{
int n;
long long x;
cin >> n;
while (n--)
{
cin >> x;
cout << sol(x);
}
return 0;
}
[/cpp]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

wiktor
New poster
Posts: 5
Joined: Wed Sep 22, 2004 6:13 pm
Two (at least) errors:
* no new line "\n" after each test case
* you print a decimal number instead of digt

chceck this

1
55

my output : 1

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
yeah,i got what u mean,thanx so much
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
What is the output for the following input set?

Input:

Code: Select all

``````10
1345262
78812653
526374512
2100999900
67281
84
764129000
128656729
89879872
554267711``````
Ami ekhono shopno dekhi...
HomePage

Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:
The output is

Code: Select all

``````7
4
3
7
3
2
1
3
6
1``````

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Thanks for the reply Krzysztof Duleba, I got it Accepted.

Thanks again...
Ami ekhono shopno dekhi...
HomePage

tRipper
New poster
Posts: 22
Joined: Sun Mar 13, 2005 5:04 pm
Location: out there
What's the output for the following input?

Code: Select all

``````3
2147483647
9045
123456789
``````
My program (WA) gives

Code: Select all

``````2
9
3
``````
If I am out of my mind, it's all right with me.