Page 7 of 14
Posted: Fri Nov 25, 2005 8:46 am
by Solaris
hello smilitude,
Your program is quite alright ... infact it has a much better running time than my own program

. But you need to change a few lines to avoid WA
Check the following line, you are printing an extra blank line for the case of e.g. 49!
But even after fixing this bug you will get PE.
Change :
To:
Code: Select all
printf("%3d! =",input); //Extra space removed
I think you will get AC pretty ezly now, and so will others viewing this post. So plz remove your code after you get AC.
Posted: Sun Nov 27, 2005 8:03 pm
by smilitude
thanks a lot solaris!!
i got ac!! you dont know, how much shouting i did in last two minutes!!
and... i got more wa's ... you gave me the courage to post them!
thanks a lot!!!!
Posted: Sun Nov 27, 2005 8:09 pm
by Solaris
My pleasure

Posted: Thu Dec 08, 2005 11:06 pm
by jaracz
93 isn't prime
Posted: Sun Jan 29, 2006 9:37 am
by nukeu666
help needed with my code
it gives no extra lines that i can see
Code: Select all
#include<stdio.h>
int main()
{
hmm
}
Code: Select all
[root@nehru ~]# ./a.out <in1
2! = 1
10! = 8 4 2 1
32! = 31 14 7 4 2 2 1 1 1 1 1
45! = 41 21 10 6 4 3 2 2 1 1 1 1 1 1
52! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
64! = 63 30 14 10 5 4 3 3 2 2 2 1 1 1 1
1 1 1
78! = 74 36 18 12 7 6 4 4 3 2 2 2 1 1 1
1 1 1 1 1 1
98! = 95 46 22 16 8 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1
100! = 97 48 24 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1
Posted: Mon Jan 30, 2006 5:02 am
by neno_uci
The output you posted here is not real, at least it's not given by the program you posted

, I tried the following test case:
your output:
Code: Select all
100! = 97 48 24 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1 0
correct output:
Code: Select all
100! = 97 48 24 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1
forget about the spaces..., and note the extra 0 in your output, best wishes,
Yandry.
Posted: Mon Jan 30, 2006 6:43 am
by chunyi81
Hmm... nukeu666. I ran your code you posted with the input you have given and got an arithmetic exception when 98 was input to your program.
This is the output I got:
Code: Select all
2! = 1
10! = 8 4 2 1
32! = 31 14 7 4 2 2 1 1 1 1 1
45! = 41 21 10 6 4 3 2 2 1 1 1 1 1 1
52! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
64! = 63 30 14 10 5 4 3 3 2 2 2 1 1 1 1
1 1 1
78! = 74 36 18 12 7 6 4 4 3 2 2 2 1 1 1
1 1 1 1 1 1
98! = 95 46 22 16 8 7 5 5 4 3 3 2 2 2 2
Arithmetic Exception
I compiled your code with gcc 2.95.3 and executed your program in Unix.
Posted: Mon Jan 30, 2006 8:17 am
by nukeu666
eeeh?!
i ran it with you input and i got this (copy pasted from my putty window)
is this compiler dependent error?
Code: Select all
[root@nehru ~]# ./a.out <in3
100! = 97 48 24 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1
[root@nehru ~]# cat in3
100
0
[root@nehru ~]#
98! is also working fine
Code: Select all
98! = 95 46 22 16 8 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1
Code: Select all
[root@nehru ~]# gcc --version
gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
edit....hm...got a floating point exception when using same input/code in gcc4.0.3 at 98! *confoosed*
damn...i give up...cant figure out why the floating point exception is coming...there certainly is no divide by zero X-(
Posted: Mon Jan 30, 2006 11:06 am
by mf
Your primes[] array contains primes up to 97. What do you think happens in this line when in>=97:
}while(primes[++testarr]<=in);
Posted: Mon Jan 30, 2006 12:53 pm
by nukeu666
i guessed the fault was ther since problem was with 97+ only...juggled a few things and works now
thanks
160 wa plz help
Posted: Tue Feb 07, 2006 12:54 pm
by yogeshgo05
hi guys ,
i don't no why i get wa
give me some failing test cases or the format is wrongly printed...
Code: Select all
# include <conio.h>
#include<iostream.h>
#include<math.h>
int main()
{
long long i,k;
long long n;
long long a[100];
long long m,sum,j;
a[0]=2;a[1]=3;
while(cin>>j)
{ k=2;
if(j==0)break;
if(j==2){cout<<"2! =1\n"; continue;}
if(j==3){cout<<"3! =1 1 1\n";continue;}
for(n=4;n<j;n++)
{
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0){i=0;break;}
}
if(i!=0)a[k++]=n;
}
cout<<j<<"! =";
for(m=0;m<k;m++)
{ //cout<<a[m]<<"\n";
sum=0;
for(i=1;i<35;i++)
{
sum+=j/pow(a[m],i);
}
cout<<sum<<" ";
}
cout<<"\n";
}
return 0;
}
Posted: Tue Feb 07, 2006 3:41 pm
by chunyi81
A very careless mistake. Given the input:
You code outputs:
But correct output is:
Also, the way you format your output is wrong, even for the sample input in the problem. And is this the same source code you submitted to the judge? This code you posted will give a compile error rather than a wrong answer. conio.h is not recognized by gcc, the compiler used here in this judge. I also had problems compiling your code with my g++ 2.95 compiler (same version as this judge's g++ compiler) with some warning messages about iostream.h. It should be iostream. And you also left out the using namespace std.
Please read the output specifications carefully here:
http://online-judge.uva.es/p/v1/160.html
Posted: Tue Feb 07, 2006 4:12 pm
by yogeshgo05
hi ....thanks,
i use turbo c++ ide hence i normally write conio.h but while submitted the code i remove it off,
cout<<"3 1 1 \n";
i have changed loop
for(n=4;n<=j;n++)
still its a wa may be its a wrong formatting of the o/p;
any way thanks man,i m still a begginer
Posted: Tue Feb 07, 2006 5:05 pm
by yogeshgo05
hi this is my rectified code , could u plz help i still get wa......15 submissons already
Code: Select all
#include<stdio.h>
#include<iostream.h>
#include<math.h>
int main()
{
long long i,k;
long long n;
long long a[101];
long long m,sum,j;
a[0]=2;a[1]=3;
while(cin>>j)
{ k=2;
if(j==0)break;
if(j==2){cout<<"2! = 1\n"; continue;}
if(j==3){cout<<"3! = 1 1 \n";continue;}
for(n=4;n<=j;n++)
{
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0){i=0;break;}
}
if(i!=0)a[k++]=n;
}
cout<<j<<"! =";
for(m=0;m<k;m++)
{ //cout<<a[m]<<"\n";
sum=0;
for(i=1;i<25;i++)
{
sum+=j/pow(a[m],i);
}
if(sum==0)break;
if(m>14)cout<<"\n ";
printf("%3ld",sum);
}
cout<<"\n";}
return 0;
}
Posted: Tue Feb 07, 2006 7:02 pm
by Solaris
hello yogeshgo05
You have actually solved the hard part but the format of your output is not according to the problem statement.
Try changing the following line:
To:
Code: Select all
if(m && (m%15) == 0) printf("\n ");
I hope u understand what i mean.