495 Why WA??

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

495 Why WA??

Postby trashmai » Thu Sep 30, 2004 9:37 pm

I've tried again and again for this problem, and always got WAs.

And I've modified my code several times, check the answer with friends, did something like that all night, but i just can't figure it out why.

I've also tried some different OS, different compiler..just don't know..don't understand..

Or does this problem have some special requirement?

[c]

#include <stdio.h>

long num1[400];
long num2[400];

struct {
long v[400];
int l;
} fibo[5002];

int l=1;
int i=0,j=1,k,maxn;

void plus(long *num1,long *num2,int *l){
int i;
for (i=0;i<*l;i++){
num1[i]=num1[i]+num2[i];
if (num1[i]>=10000) {
if (i == (*l)-1)
(*l)++;
num1[i] %= 10000;
num1[i+1]+=1;
}
}
if (num1[*l+1]!=0) (*l)++;
}


void getfib(int n){
for (i=(maxn/2)+(maxn%2)-1;i<n/2+n%2-1;i++){
plus(num1,num2,&l);
for (k=0;k<l;k++){
fibo[j].v[k]=num1[k];
fibo[j].l=l;
}
j++;
plus(num2,num1,&l);
for (k=0;k<l;k++){
fibo[j].v[k]=num2[k];
fibo[j].l=l;
}
j++;
}
maxn=n;
}

int main(void){

int n;
num1[0]=0;
num2[0]=1;

while (scanf("%d",&n)==1){

if (n>maxn) getfib(n);

printf("The Fibonacci number for %d is ",n);
if (n==0) {printf("0\n");}
else if (n==1) {printf("1\n");}
else{
for (i=fibo[n-1].l-1;i>=0;i--){
if (i!=fibo[n-1].l-1){
if (fibo[n-1].v[i]/1000 == 0){
printf("0");
if (fibo[n-1].v[i]/100 == 0){
printf("0");
if (fibo[n-1].v[i]/10 == 0){
printf("0");
if (fibo[n-1].v[i] == 0){
printf("0");
}
}
}
}
}
if ((i!=fibo[n-1].l-1)||(fibo[n-1].v[fibo[n-1].l-1]!=0)||(i==0)) printf("%ld",fibo[n-1].v[i]);
}
printf("\n");
}
}
return 0;
}

[/c]
trashmai
New poster
 
Posts: 2
Joined: Thu Sep 30, 2004 9:10 pm

Postby Ghust_omega » Fri Oct 01, 2004 5:46 am

Hi!! trashmai this bug was hard to take this are only a few inputs for what your programs give the bad ouputs, there are a lot of more and you have to check your code carefully to see whats the error
Inputs:
Code: Select all
229
331
676
707
883
1259
1281
1354
1457
1482
1639
1763
2074
2271
2454



your outputs:
Code: Select all
The Fibonacci number for 229 is 3226150438368547835801863092826500000354271239929
The Fibonacci number for 331 is 6689966153880050315310000081241745415306766517246774551964595292186469
The Fibonacci number for 676 is 843645135740916443113832571217701196011659994669538939065731942674862905
3974339797159317419590735252363050000074026438339415322804865241443907
The Fibonacci number for 707 is 253966629073281232189337259218152410852422549133431257743959463526688432
142507262909546057630000094211512963232351039521888530847428153536779619
22313
The Fibonacci number for 883 is 153674333621065775410236648042084662848933007661143980817104150291913024
432550388836715205238203065555551077282341319994362147315439893310354801
174814919204532789834000009134843095074197
The Fibonacci number for 1259 is 583383407137109552695513219117000889452560276181560389185306406504719105
574248327539873798779599048248777807405108011571417504604341139469749502
951032384890088109110694199323385025755211080077569007602267187819396794
861000006853565220909996090221575992411145026841
The Fibonacci number for 1281 is 231037330581201613541810332878320047610968044603927904276201130919668151
578332280814068820905015484222088668506982436676293106266035951346124145
138641474888037614360000011519986001438137772940652463498766997454913312
61345290543473787767781052429221179160066016980283106
The Fibonacci number for 1354 is 416658164472158071807004334011404711927666607437877761909757165990522629
372073953347821825733637582667189807220000005779204928063590304756708079
368880036349918299848247305901165170141448475237090581881627034394689924
70659897525400423246616595745419783065444393918471179930961988965047
The Fibonacci number for 1457 is 139799893979028759227121500000159855130950737882832056931993444610576633
191486820314303072981531995383574898970680105991014251835508971894751737
700068014881489090339915162368380430230277494790402145025349067475687573
521289419187221479911222033678107616022967556666725944711018417118037614
388065508852973437
The Fibonacci number for 1482 is 234529700146491714106444267259079300000563822415114892210296831097700361
599439774917985459968990802695003946883045903280232786306363211148294325
030277917998033362554592572516119877030072224731922518399843586480685765
039175769695008728602465157615574612684826383120000072573172905199389544
514613676964809840319416
The Fibonacci number for 1639 is
151794965414245575475610557277367913657868530085935306898024677804332381
576028600052145775123817130102261797063133262881886719453262108729998163
976736294999445827509895136802056382838174903413894651348813115072124160
905521195128279291911391937000001882186786177559094392685074951575821648
87799547628124544188082939220697351008141459335979517261
The Fibonacci number for 1763 is 124659321435381971396290243033354856707490000029306907413118021184590814
978224710076182722066427798665925476044313148203890280058571617345860959
476669723263556029608450958579721041198777594025743381296443523734496607
988970944187171129099526952952452372797989325711379155288603825693592980
087360074901115492823372308658631509351460749939845244864514159039171977
9685843017
The Fibonacci number for 2074 is 123276664822441436802417912202266906557618363968891298464804812547681947
757546599762101329097449904139951834497802051982378337963149864691431740
062807323321653290725458035843833438209310272318105311673692785921921823
265175263222862328791594446699982499029989000006805778779220595452690751
429602631793206189081195838617678783129420515288491763988817830559379600
923971216551876929511120684553377626648465398022823371885948010159198648
407
The Fibonacci number for 2271 is 182576974275695146285730865253562912970948463826485206315031878888774112
658505557644300099714892829352811873231147915328715899859090200639020402
315250996991752328661366622635292199213633894412917233216738543821379455
006225214434028930051755328812562722869324582832961892403895965812733471
282488387377002233486518685812736841137048837090000057740990780020625243
889930085754991215013246114390093777056075882031106250250290227071112792
30143119635543337370882239064337292667715554
The Fibonacci number for 2454 is 320762929561828896801421550206212157187990950003192169549688148507307136
875401893375448890453978260944744399653349037266527236694420616552028266
145947141833427249255745627435188748719598808192743303578503677388708560
417600991443804090000037482530368830837555445098983643117766841642291685
057464047224116333200626507879039460242602181935065137363512178132953574
879432331831101753521189949148748334398851600569412041884977369262640138
305740579231107790310020056859832392975374316344797776115300505759027571
3225142472


My ouputs the diferences is for a digit in some case in others the diferences is for 2 digits
Code: Select all
The Fibonacci number for 229 is 322615043836854783580186309282650000354271239929
The Fibonacci number for 331 is 668996615388005031531000081241745415306766517246774551964595292186469
The Fibonacci number for 676 is 843645135740916443113832571217701196011659994669538939065731942674862905
397433979715931741959073525236305000074026438339415322804865241443907
The Fibonacci number for 707 is 253966629073281232189337259218152410852422549133431257743959463526688432
142507262909546057630000942115129632323510395218885308474281535367796192
2313
The Fibonacci number for 883 is 153674333621065775410236648042084662848933007661143980817104150291913024
432550388836715205238203065555551077282341319994362147315439893310354801
17481491920453278983400009134843095074197
The Fibonacci number for 1259 is 583383407137109552695513219117000889452560276181560389185306406504719105
574248327539873798779599048248777807405108011571417504604341139469749502
951032384890088109110694199323385025755211080077569007602267187819396794
86100006853565220909996090221575992411145026841
The Fibonacci number for 1281 is 231037330581201613541810332878320047610968044603927904276201130919668151
578332280814068820905015484222088668506982436676293106266035951346124145
138641474888037614360000115199860014381377729406524634987669974549133126
1345290543473787767781052429221179160066016980283106
The Fibonacci number for 1354 is 416658164472158071807004334011404711927666607437877761909757165990522629
372073953347821825733637582667189807220000057792049280635903047567080793
688800363499182998482473059011651701414484752370905818816270343946899247
0659897525400423246616595745419783065444393918471179930961988965047
The Fibonacci number for 1457 is 139799893979028759227121500001598551309507378828320569319934446105766331
914868203143030729815319953835748989706801059910142518355089718947517377
000680148814890903399151623683804302302774947904021450253490674756875735
212894191872214799112220336781076160229675566667259447110184171180376143
88065508852973437
The Fibonacci number for 1482 is 234529700146491714106444267259079300005638224151148922102968310977003615
994397749179854599689908026950039468830459032802327863063632111482943250
302779179980333625545925725161198770300722247319225183998435864806857650
391757696950087286024651576155746126848263831200007257317290519938954451
4613676964809840319416
The Fibonacci number for 1639 is 151794965414245575475610557277367913657868530085935306898024677804332381
576028600052145775123817130102261797063133262881886719453262108729998163
976736294999445827509895136802056382838174903413894651348813115072124160
905521195128279291911391937000018821867861775590943926850749515758216488
7799547628124544188082939220697351008141459335979517261
The Fibonacci number for 1763 is 124659321435381971396290243033354856707490000293069074131180211845908149
782247100761827220664277986659254760443131482038902800585716173458609594
766697232635560296084509585797210411987775940257433812964435237344966079
889709441871711290995269529524523727979893257113791552886038256935929800
873600749011154928233723086586315093514607499398452448645141590391719779
685843017
The Fibonacci number for 2074 is 123276664822441436802417912202266906557618363968891298464804812547681947
757546599762101329097449904139951834497802051982378337963149864691431740
062807323321653290725458035843833438209310272318105311673692785921921823
265175263222862328791594446699982499029989000068057787792205954526907514
296026317932061890811958386176787831294205152884917639888178305593796009
239712165518769295111206845533776266484653980228233718859480101591986484
07
The Fibonacci number for 2271 is 182576974275695146285730865253562912970948463826485206315031878888774112
658505557644300099714892829352811873231147915328715899859090200639020402
315250996991752328661366622635292199213633894412917233216738543821379455
006225214434028930051755328812562722869324582832961892403895965812733471
282488387377002233486518685812736841137048837090000577409907800206252438
899300857549912150132461143900937770560758820311062502502902270711127923
0143119635543337370882239064337292667715554
The Fibonacci number for 2454 is 320762929561828896801421550206212157187990950003192169549688148507307136
875401893375448890453978260944744399653349037266527236694420616552028266
145947141833427249255745627435188748719598808192743303578503677388708560
417600991443804090000374825303688308375554450989836431177668416422916850
574640472241163332006265078790394602426021819350651373635121781329535748
794323318311017535211899491487483343988516005694120418849773692626401383
057405792311077903100200568598323929753743163447977761153005057590275713
225142472


Hope it helps
Keep posting!! :D

Sorry for ocuped that kind of space but this is a friend that need help
:P
User avatar
Ghust_omega
Experienced poster
 
Posts: 115
Joined: Tue Apr 06, 2004 7:04 pm
Location: Venezuela

Postby trashmai » Fri Oct 01, 2004 8:54 am

Thank you!! :D

I'll be more carefull next time!!
trashmai
New poster
 
Posts: 2
Joined: Thu Sep 30, 2004 9:10 pm

Re: 495 Why WA??

Postby slash190 » Wed Feb 16, 2011 8:07 pm

if everything is right still getting WA
try making the array size 10000 instead of 5002
slash190
New poster
 
Posts: 2
Joined: Thu Feb 10, 2011 11:52 am


Return to Volume IV

Who is online

Users browsing this forum: No registered users and 1 guest