547 - DDF

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

Moderator: Board moderators

Post Reply
AlexandreN
New poster
Posts: 27
Joined: Sun Jul 07, 2002 6:46 pm
Location: Campina Grande - Brazil
Contact:

547 - DDF

Post by AlexandreN »

Can you tell-me if this output is correct ?

INPUT

0 3000
2 3000
3000 2
100 200
200 100
1000 3000
2 1000
1000 2
15 15
14 16
16 14
2 15

OUTPUT

Input1: 0 3000
Output1: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input2: 2 3000
Output2: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input3: 3000 2
Output3: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input4: 100 200
Output4: 162 66 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input5: 200 100
Output5: 162 66 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input6: 1000 3000
Output6: 1104 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input7: 2 1000
Output7: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input8: 1000 2
Output8: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input9: 15 15
Output9: 15
Input10: 14 16
Output10: 16 22 9 13 5 6 12 19 11 3 4 7 8 15
Input11: 16 14
Output11: 16 22 9 13 5 6 12 19 11 3 4 7 8 15
Input12: 2 15
Output12: 10 9 13 5 6 12 19 11 3 4 7 8 15
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Yes, my accepted solution produces the same output as yours.
AlexandreN
New poster
Posts: 27
Joined: Sun Jul 07, 2002 6:46 pm
Location: Campina Grande - Brazil
Contact:

Post by AlexandreN »

I found my mistake, got it accepted.
mrtamtam
New poster
Posts: 5
Joined: Wed Jan 15, 2003 9:50 pm

547 - DDF

Post by mrtamtam »

i don't know where I get wrong..............
any good test case ?
I have search the previous post about 547..........
I have the same output as him...........
I don't know where is the problem.......
Please help..............
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Hi... :D

You can try these inputs:

Code: Select all

1 1
712 710
123 999
600 500
OUPUTS

Code: Select all

Input1: 1 1
Output1: 1
Input2: 712 710
Output2:  712 72 69 24 33 12 19 11 3 4 7 8 15
Input3: 123 999
Output3: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Input4: 600 500
Output4: 518 66 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
Good Luck! :lol:

angga888 :lol:
poulls
New poster
Posts: 3
Joined: Mon Jul 21, 2003 12:54 pm

547 TLE

Post by poulls »

I don't know why it got TLE here is my code
Can antone help me ?

#include<iostream.h>
#include<math.h>

int add(int n)
{
if (n<10)
return n;
else
{
int t=0;
while(n)
{
t+=n%10;
n=n/10;
}
return t;
}
}

int main()
{
int m,n,mm,nn,i,j,nt=1;
int now,num,sum;
int a[1000],maxa[1000],max;
while(cin>>m>>n)
{
mm=m<n?m:n;
nn=m>n?m:n;
max=0;
for (i=mm;i<=nn;i++)
{
num=1;
now=i;
a[0]=0;
a[num]=now;
num++;

while(a[num-1]!=a[num-2])
{
sum=0;
for (j=1;j<sqrt(now);j++)
if (now%j==0)
{
sum+=add(j);
sum+=add(now/j);
}
if (j*j==now)
sum+=add(j);
a[num]=sum;
now=sum;
num++;
}
if (num-2>max)
{
max=num-2;
for (j=1;j<=max;j++)
maxa[j]=a[j];
}
}
cout<<"Input"<<nt<<": "<<m<<" "<<n<<endl;
cout<<"Output"<<nt<<":";
for (i=1;i<=max;i++)
{
cout<<" "<<maxa;
}
cout<<endl;
nt++;
}
return 0;
}
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Post by Joseph Kurniawan »

Well, there's one cheat method. You should calculate the length of allof the possible input (1 - 3000) and then store their length in array :
int length[3010]={0,1,.....}

Good Luck!!
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »


Thank you Subeen Bhai. I should try to remove all the ambiguities from my src.
Thank you again.
Src is cut off as it gets ac.
Last edited by anupam on Mon Sep 29, 2003 7:46 am, edited 2 times in total.
"Everything should be made simple, but not always simpler"
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen »

anupam: i found a bug in the code.

replace the line

Code: Select all

printf("Input%d: %d %d\nOutput%d: ",cas,a,b,cas++);
by

Code: Select all

printf("Input%d: %d %d\nOutput%d: ",cas++,a,b,cas);
Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh
Contact:

Re: 547 - DDF

Post by Shafaet_du »

Try to pass this samples:

15 15
Input1: 15 15
Output1: 15
1 1
Input2: 1 1
Output2: 1
0 1
Input3: 0 1
Output3: 0
1 3000
Input4: 1 3000
Output4: 924 168 102 36 46 18 30 27 22 9 13 5 6 12 19 11 3 4 7 8 15
1 1
Input5: 1 1
Output5: 1
0 0
Input6: 0 0
Output6: 0
Post Reply

Return to “Volume 5 (500-599)”