All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
Solaris
Learning poster
Posts: 99 Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:
Post
by Solaris » Fri Nov 25, 2005 8:46 am
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.
Where's the "Any" key?
smilitude
Experienced poster
Posts: 137 Joined: Fri Jul 01, 2005 12:21 am
Post
by smilitude » Sun Nov 27, 2005 8:03 pm
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!!!!
fahim
#include <smile.h>
Solaris
Learning poster
Posts: 99 Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:
Post
by Solaris » Sun Nov 27, 2005 8:09 pm
My pleasure
Where's the "Any" key?
jaracz
Learning poster
Posts: 79 Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland
Post
by jaracz » Thu Dec 08, 2005 11:06 pm
93 isn't prime
keep it real!
nukeu666
New poster
Posts: 44 Joined: Sun Feb 13, 2005 1:13 am
Location: India
Contact:
Post
by nukeu666 » Sun Jan 29, 2006 9:37 am
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
Last edited by
nukeu666 on Mon Jan 30, 2006 12:51 pm, edited 1 time in total.
google
neno_uci
Experienced poster
Posts: 104 Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba
Post
by neno_uci » Mon Jan 30, 2006 5:02 am
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.
chunyi81
A great helper
Posts: 293 Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore
Post
by chunyi81 » Mon Jan 30, 2006 6:43 am
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.
nukeu666
New poster
Posts: 44 Joined: Sun Feb 13, 2005 1:13 am
Location: India
Contact:
Post
by nukeu666 » Mon Jan 30, 2006 8:17 am
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-(
google
mf
Guru
Posts: 1244 Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
Post
by mf » Mon Jan 30, 2006 11:06 am
Your primes[] array contains primes up to 97. What do you think happens in this line when in>=97:
}while(primes[++testarr]<=in);
nukeu666
New poster
Posts: 44 Joined: Sun Feb 13, 2005 1:13 am
Location: India
Contact:
Post
by nukeu666 » Mon Jan 30, 2006 12:53 pm
i guessed the fault was ther since problem was with 97+ only...juggled a few things and works now
thanks
google
yogeshgo05
New poster
Posts: 47 Joined: Sun Nov 27, 2005 12:43 pm
Post
by yogeshgo05 » Tue Feb 07, 2006 12:54 pm
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;
}
chunyi81
A great helper
Posts: 293 Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore
Post
by chunyi81 » Tue Feb 07, 2006 3:41 pm
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
yogeshgo05
New poster
Posts: 47 Joined: Sun Nov 27, 2005 12:43 pm
Post
by yogeshgo05 » Tue Feb 07, 2006 4:12 pm
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
yogeshgo05
New poster
Posts: 47 Joined: Sun Nov 27, 2005 12:43 pm
Post
by yogeshgo05 » Tue Feb 07, 2006 5:05 pm
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;
}
Solaris
Learning poster
Posts: 99 Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:
Post
by Solaris » Tue Feb 07, 2006 7:02 pm
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.
Where's the "Any" key?