## 495 Why WA??

Moderator: Board moderators

### 495 Why WA??

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

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
`2293316767078831259128113541457148216391763207422712454`

Code: Select all
`The Fibonacci number for 229 is 3226150438368547835801863092826500000354271239929The Fibonacci number for 331 is 6689966153880050315310000081241745415306766517246774551964595292186469The Fibonacci number for 676 is 8436451357409164431138325712177011960116599946695389390657319426748629053974339797159317419590735252363050000074026438339415322804865241443907The Fibonacci number for 707 is 25396662907328123218933725921815241085242254913343125774395946352668843214250726290954605763000009421151296323235103952188853084742815353677961922313The Fibonacci number for 883 is 153674333621065775410236648042084662848933007661143980817104150291913024432550388836715205238203065555551077282341319994362147315439893310354801174814919204532789834000009134843095074197The Fibonacci number for 1259 is 583383407137109552695513219117000889452560276181560389185306406504719105574248327539873798779599048248777807405108011571417504604341139469749502951032384890088109110694199323385025755211080077569007602267187819396794861000006853565220909996090221575992411145026841The Fibonacci number for 1281 is 23103733058120161354181033287832004761096804460392790427620113091966815157833228081406882090501548422208866850698243667629310626603595134612414513864147488803761436000001151998600143813777294065246349876699745491331261345290543473787767781052429221179160066016980283106The Fibonacci number for 1354 is 41665816447215807180700433401140471192766660743787776190975716599052262937207395334782182573363758266718980722000000577920492806359030475670807936888003634991829984824730590116517014144847523709058188162703439468992470659897525400423246616595745419783065444393918471179930961988965047The Fibonacci number for 1457 is 139799893979028759227121500000159855130950737882832056931993444610576633191486820314303072981531995383574898970680105991014251835508971894751737700068014881489090339915162368380430230277494790402145025349067475687573521289419187221479911222033678107616022967556666725944711018417118037614388065508852973437The Fibonacci number for 1482 is 234529700146491714106444267259079300000563822415114892210296831097700361599439774917985459968990802695003946883045903280232786306363211148294325030277917998033362554592572516119877030072224731922518399843586480685765039175769695008728602465157615574612684826383120000072573172905199389544514613676964809840319416The Fibonacci number for 1639 is 15179496541424557547561055727736791365786853008593530689802467780433238157602860005214577512381713010226179706313326288188671945326210872999816397673629499944582750989513680205638283817490341389465134881311507212416090552119512827929191139193700000188218678617755909439268507495157582164887799547628124544188082939220697351008141459335979517261The Fibonacci number for 1763 is 1246593214353819713962902430333548567074900000293069074131180211845908149782247100761827220664277986659254760443131482038902800585716173458609594766697232635560296084509585797210411987775940257433812964435237344966079889709441871711290995269529524523727979893257113791552886038256935929800873600749011154928233723086586315093514607499398452448645141590391719779685843017The Fibonacci number for 2074 is 123276664822441436802417912202266906557618363968891298464804812547681947757546599762101329097449904139951834497802051982378337963149864691431740062807323321653290725458035843833438209310272318105311673692785921921823265175263222862328791594446699982499029989000006805778779220595452690751429602631793206189081195838617678783129420515288491763988817830559379600923971216551876929511120684553377626648465398022823371885948010159198648407The Fibonacci number for 2271 is 18257697427569514628573086525356291297094846382648520631503187888877411265850555764430009971489282935281187323114791532871589985909020063902040231525099699175232866136662263529219921363389441291723321673854382137945500622521443402893005175532881256272286932458283296189240389596581273347128248838737700223348651868581273684113704883709000005774099078002062524388993008575499121501324611439009377705607588203110625025029022707111279230143119635543337370882239064337292667715554The Fibonacci number for 2454 is 3207629295618288968014215502062121571879909500031921695496881485073071368754018933754488904539782609447443996533490372665272366944206165520282661459471418334272492557456274351887487195988081927433035785036773887085604176009914438040900000374825303688308375554450989836431177668416422916850574640472241163332006265078790394602426021819350651373635121781329535748794323318311017535211899491487483343988516005694120418849773692626401383057405792311077903100200568598323929753743163447977761153005057590275713225142472`

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 322615043836854783580186309282650000354271239929The Fibonacci number for 331 is 668996615388005031531000081241745415306766517246774551964595292186469The Fibonacci number for 676 is 843645135740916443113832571217701196011659994669538939065731942674862905397433979715931741959073525236305000074026438339415322804865241443907The Fibonacci number for 707 is 2539666290732812321893372592181524108524225491334312577439594635266884321425072629095460576300009421151296323235103952188853084742815353677961922313The Fibonacci number for 883 is 15367433362106577541023664804208466284893300766114398081710415029191302443255038883671520523820306555555107728234131999436214731543989331035480117481491920453278983400009134843095074197The Fibonacci number for 1259 is 58338340713710955269551321911700088945256027618156038918530640650471910557424832753987379877959904824877780740510801157141750460434113946974950295103238489008810911069419932338502575521108007756900760226718781939679486100006853565220909996090221575992411145026841The Fibonacci number for 1281 is 2310373305812016135418103328783200476109680446039279042762011309196681515783322808140688209050154842220886685069824366762931062660359513461241451386414748880376143600001151998600143813777294065246349876699745491331261345290543473787767781052429221179160066016980283106The Fibonacci number for 1354 is 4166581644721580718070043340114047119276666074378777619097571659905226293720739533478218257336375826671898072200000577920492806359030475670807936888003634991829984824730590116517014144847523709058188162703439468992470659897525400423246616595745419783065444393918471179930961988965047The Fibonacci number for 1457 is 13979989397902875922712150000159855130950737882832056931993444610576633191486820314303072981531995383574898970680105991014251835508971894751737700068014881489090339915162368380430230277494790402145025349067475687573521289419187221479911222033678107616022967556666725944711018417118037614388065508852973437The Fibonacci number for 1482 is 2345297001464917141064442672590793000056382241511489221029683109770036159943977491798545996899080269500394688304590328023278630636321114829432503027791799803336255459257251611987703007222473192251839984358648068576503917576969500872860246515761557461268482638312000072573172905199389544514613676964809840319416The Fibonacci number for 1639 is 1517949654142455754756105572773679136578685300859353068980246778043323815760286000521457751238171301022617970631332628818867194532621087299981639767362949994458275098951368020563828381749034138946513488131150721241609055211951282792919113919370000188218678617755909439268507495157582164887799547628124544188082939220697351008141459335979517261The Fibonacci number for 1763 is 124659321435381971396290243033354856707490000293069074131180211845908149782247100761827220664277986659254760443131482038902800585716173458609594766697232635560296084509585797210411987775940257433812964435237344966079889709441871711290995269529524523727979893257113791552886038256935929800873600749011154928233723086586315093514607499398452448645141590391719779685843017The Fibonacci number for 2074 is 12327666482244143680241791220226690655761836396889129846480481254768194775754659976210132909744990413995183449780205198237833796314986469143174006280732332165329072545803584383343820931027231810531167369278592192182326517526322286232879159444669998249902998900006805778779220595452690751429602631793206189081195838617678783129420515288491763988817830559379600923971216551876929511120684553377626648465398022823371885948010159198648407The Fibonacci number for 2271 is 1825769742756951462857308652535629129709484638264852063150318788887741126585055576443000997148928293528118732311479153287158998590902006390204023152509969917523286613666226352921992136338944129172332167385438213794550062252144340289300517553288125627228693245828329618924038959658127334712824883873770022334865186858127368411370488370900005774099078002062524388993008575499121501324611439009377705607588203110625025029022707111279230143119635543337370882239064337292667715554The Fibonacci number for 2454 is 320762929561828896801421550206212157187990950003192169549688148507307136875401893375448890453978260944744399653349037266527236694420616552028266145947141833427249255745627435188748719598808192743303578503677388708560417600991443804090000374825303688308375554450989836431177668416422916850574640472241163332006265078790394602426021819350651373635121781329535748794323318311017535211899491487483343988516005694120418849773692626401383057405792311077903100200568598323929753743163447977761153005057590275713225142472`

Hope it helps
Keep posting!!

Sorry for ocuped that kind of space but this is a friend that need help

Ghust_omega
Experienced poster

Posts: 115
Joined: Tue Apr 06, 2004 7:04 pm
Location: Venezuela

Thank you!!

I'll be more carefull next time!!
trashmai
New poster

Posts: 2
Joined: Thu Sep 30, 2004 9:10 pm

### Re: 495 Why WA??

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

### Who is online

Users browsing this forum: No registered users and 1 guest