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?
10015 - Joseph's Cousin
Moderator: Board moderators
Re: 10015 - Joseph's Cousin
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.
Use debuggers to find what's wrong exactly.
uva problem no:10015
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;
}
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
plz help me about this problem,i have posted my code earlier but no help from any1..


-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva problem no:10015
For n=1 the answer is 1, your program prints 0.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 19
- Joined: Mon Jan 07, 2013 9:30 am
10015 - Joseph's Cousin
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!
worst case test (1 2 3 ... to 3501 done by using commented code): around 30 sec (10 sec allowed)

code deleted after AC to prevent copies!

Last edited by theemathas on Thu Jan 10, 2013 7:48 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10015 - Joseph's Cousin
Read mf's post in this thread.
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10015 - Joseph's Cousin
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 

Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?