10015 - Joseph's Cousin

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sayem
New poster
Posts: 7
Joined: Sun Jul 12, 2009 10:30 pm

10015 - Joseph's Cousin

Post by sayem » Wed Aug 05, 2009 8:22 pm

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?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10015 - Joseph's Cousin

Post by mf » Thu Aug 06, 2009 6:50 am

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.

vwxy825
New poster
Posts: 1
Joined: Mon Aug 24, 2009 6:57 am
Contact:

supervisor Road

Post by vwxy825 » Sat Sep 12, 2009 7:13 am


snape
New poster
Posts: 5
Joined: Sat Dec 03, 2011 4:18 pm

uva problem no:10015

Post by snape » Sat Dec 03, 2011 5:06 pm

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;

}

snape
New poster
Posts: 5
Joined: Sat Dec 03, 2011 4:18 pm

uva problem no 10015

Post by snape » Sun Dec 04, 2011 12:59 pm

plz help me about this problem,i have posted my code earlier but no help from any1..
:(

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: uva problem no:10015

Post by brianfry713 » Tue Jan 10, 2012 1:50 am

For n=1 the answer is 1, your program prints 0.
Check input and AC output for thousands of problems on uDebug!

theemathas
New poster
Posts: 19
Joined: Mon Jan 07, 2013 9:30 am

10015 - Joseph's Cousin

Post by theemathas » Mon Jan 07, 2013 9:36 am

got TLE
worst case test (1 2 3 ... to 3501 done by using commented code): around 30 sec (10 sec allowed)
:D I got this solved by a chat in uhunt
code deleted after AC to prevent copies! :wink:
Last edited by theemathas on Thu Jan 10, 2013 7:48 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10015 - Joseph's Cousin

Post by brianfry713 » Mon Jan 07, 2013 10:12 am

Read mf's post in this thread.
Check input and AC output for thousands of problems on uDebug!

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10015 - Joseph's Cousin

Post by DD » Tue Feb 19, 2013 5:26 am

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 :o
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?
If so, you need to read Elements of Programming Interviews.

Post Reply

Return to “Volume 100 (10000-10099)”