Page 2 of 2
10015 - Joseph's Cousin
Posted: Wed Aug 05, 2009 8:22 pm
by sayem
hey mf
i have use this input :
2 4 5 6 7 10 100 200 300 500 1000 2000 3000 3400 3501 0
and here is th output :
1
4
1
4
3
1
60
140
278
115
897
344
1613
2238
2326
what's the problem in my code? i can't detect it can u tell?
why is showing all 3?
Re: 10015 - Joseph's Cousin
Posted: Thu Aug 06, 2009 6:50 am
by mf
Most likely it's in your sieve() procedure. And it's too long for such a simple task.
Use debuggers to find what's wrong exactly.
supervisor Road
Posted: Sat Sep 12, 2009 7:13 am
by vwxy825
uva problem no:10015
Posted: Sat Dec 03, 2011 5:06 pm
by snape
uva problem no:10015
still got WA,but dont know why?
here is my code:
#include<stdio.h>
#include<math.h>
#define max 3520
int p[max],ab[max],v[max],s,f,g,h,m,x,w,mm;
void sieve()
{
long i,j,c=0,x=0,b=0;
for(i=2;i<max;i++)
p=1;
for(i=2;i<=sqrt(max); )
{
for(j=i+i;j<=max;j+=i)
p[j]=0;
i++;
for(;!p;i++);
}
for(i=0;i<=max;i++)
{
if(p) //This 2 lines for checking the number of primes between 0 & 10000000.
{
ab=i;
b++;
}
}
mm=b;
}
void cutting(int o,int w)
{
int n,a[max],pi,ii,jj,f,k,g;
f=o;
while(f>1)
{
for(jj=0;jj<mm;jj++){
n=ab[jj];
if(n==0)
break;
while(n>f)
n=n-f;
n=n-1;
pi=n;
v[n]='\0';
n=n+1;
for(ii=0;n<=w;ii++)
{
a[ii]=v[n];
n++;
}
pi=pi-1;
for(k=0;k<=pi;k++)
{
while(v[k]=='\0')
k++;
if(k>pi)
break;
a[ii]=v[k];
ii++;
}
for(f=0;f<ii;f++)
v[f]=a[f];
w=w-1;
if(f==1)
break;
}
if(f==1)
break;
}
printf("%d\n",v[f]);
}
int main()
{
sieve();
while(1){
scanf("%ld",&s);
getchar();
if(s==0)
break;
for(f=1;f<=s;f++)
{
v[f-1]=f;
}
f=f-1;
w=s-1;
cutting(f,w);
}
return 0;
}
uva problem no 10015
Posted: Sun Dec 04, 2011 12:59 pm
by snape
plz help me about this problem,i have posted my code earlier but no help from any1..

Re: uva problem no:10015
Posted: Tue Jan 10, 2012 1:50 am
by brianfry713
For n=1 the answer is 1, your program prints 0.
10015 - Joseph's Cousin
Posted: Mon Jan 07, 2013 9:36 am
by theemathas
got TLE
worst case test (1 2 3 ... to 3501 done by using commented code): around 30 sec (10 sec allowed)

I got this solved by a chat in uhunt
code deleted after AC to prevent copies!

Re: 10015 - Joseph's Cousin
Posted: Mon Jan 07, 2013 10:12 am
by brianfry713
Read mf's post in this thread.
Re: 10015 - Joseph's Cousin
Posted: Tue Feb 19, 2013 5:26 am
by DD
Even I used offline-built table to solve this, but I still noticed that there are people can solve this problem using 0.000 secs
