10190 - Divide, But Not Quite Conquer!

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

Moderator: Board moderators

Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho »

Rocky,

You can try the input I post below and check if your program
produces the same output as mine ( my program is
an ACC program ).

By the way, you may also check this thread
http://online-judge.uva.es/board/viewtopic.php?t=2474


INPUT

Code: Select all

127  0  
12 7 
127 1
1 1 
22 0
0 0
   0 1 
0 9
125 5 
30    3 
80  2 
81 3 
    64 4 
64 2 
64 1 
60 1 
60 2 
60 3 
60 4 
60 5
       1000000000 500 
1999999999 9 
387420489 9 
387420489 8 
387420489 10 
312500000 50 
312500000 51 
312500000 49 
0 0 
0 1 
1 0 
1 1
22 1
15 1
1 88 
88 1 
1 1
12 1
1 12
100 100
100 50
256 16
256 4
333333 333
4096 16
1024 16

OUTPUT

Code: Select all

Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
125 25 5 1
Boring!
Boring!
81 27 9 3 1
64 16 4 1
64 32 16 8 4 2 1
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
387420489 43046721 4782969 531441 59049 6561 729 81 9 1
Boring!
Boring!
312500000 6250000 125000 2500 50 1
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
Boring!
100 1
Boring!
256 16 1
256 64 16 4 1
Boring!
4096 256 16 1
Boring!
I hope this helps.
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho »

Just to confirm.

The output of DERK ( Posted: Sat Mar 29, 2003 2:20 pm ) is correct.
My ACC program gives same
output when I use the input he/she has posted.

The remark from GITS is correct.
If N is equal to 1 we should directly print "Boring!" no matter
what the value of M is.
That's not very clear from the problem statement, I agree.
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

Acc 10190

Post by Rocky »

Thank's Sedefcho For Your Reply.
I GOt Acc Now.
thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

10190 , please help me i am getting run time error

Post by thinker_bd »

i got accepted
Last edited by thinker_bd on Thu Jun 16, 2005 7:57 pm, edited 1 time in total.
sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar »

Change the array limit to something bigger and check, its usually array indices out of bound that would give you a RTE/SEGfault.
And dont use`//' for comments if you are to submit it as a C program.
thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

10190 Still run time error

Post by thinker_bd »

my program is accepted so i remove my code
Last edited by thinker_bd on Thu Jun 16, 2005 8:01 pm, edited 1 time in total.
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

You should check if m != 0!!!!!!!!

Remember that we cannot devide through 0!
That's why you're gettin' RTE
You don't have to enlarge your array instead

Have a nice WA:)
Regards
keep it real!
thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

10190 after checking m=0 and array but till RTE

Post by thinker_bd »

code removed
Last edited by thinker_bd on Thu Jun 16, 2005 8:37 pm, edited 1 time in total.
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

Thinker BD !!

Post by Raj Ariyan »

Hi Thinker Bangladesh,
You wrote --
while(1)
{
if(flag==1)
break;

if((n%m)!=0)
{
flag=1;
break;
}
array=n/m;
n=n/m;
if(n==1)
break;
i++;
}


I think this is not ok, sometime it may gets overflow or (n%0). Though if u correct it then u will get P.E, rite ? Why u make it so complex, if n is not proper power m then boring, else just print

Code: Select all

printf("%d",n);
while(n!=1)
     printf(" %d",(n/=m));
printf("\n");
Isnt it so easy ??? Always think in a Simple way !!!
Some Love Stories Live Forever ....
thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

Post by thinker_bd »

mr RAJ i dont understand what u mean by

"if n is not proper power m then boring........"
............
...........

what is proper power how i check it
please can say me clearly how i implement this line
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

10190

Post by Raj Ariyan »

Hi Thinker,
Let see the first input. In our first input there is n=125,m=5. In this input n is a proper power of 5, i means 5^3=125, right ? if so then just implement what i say in my last thread. If no, say abt our second input, n=30,m=3, there is no power which makes m^x=n, so the output should be "boring". Same things also happens with third input. And the last input, n=81,m=3, then 3^4=81, so u have to print 3^4 , 3^3, 3^2, 3^1, 3^0. Understand ? Good Luck.
Some Love Stories Live Forever ....
thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

but TLE

Post by thinker_bd »

my code removed
Last edited by thinker_bd on Thu Jun 16, 2005 8:05 pm, edited 1 time in total.
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

Hi Thinker

Post by Raj Ariyan »

Hi,
Try to understand. The max limit is 2000000000, so when compare the value with power sometime it may exceeds int limit. So use unsingned int. In ur while condition u take input as %lu, then u print the value with
%d !!!!! Another things make a check in ur while loop
if(m<2 || n<2)
break;

So make it:-

Code: Select all

while(1) 
		{ 
			if(n<2 || m<2)
				break;

			tmp=(int)pow(m,i); 
			if(tmp>n) 
				break; 
			if(tmp==n) 
			{ 
				flag=1; 
				break; 
			} 
			i++; 
		} 
Hope it helps.
Some Love Stories Live Forever ....
thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

THANX MR RAJ

Post by thinker_bd »

THANX MR RAJ , AT LAST I GOT ACCEPTED IN 10190 AFTER 25!! SUBMISSION.
59557RC
New poster
Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm
Location: bangladesh
Contact:

10190-pls pls help!

Post by 59557RC »

i made more than 20 submissions 4 this pob. i dont find the mistake why it gets WA.any1 pls help me:

#include<stdio.h>
#include<math.h>

int main()
{
long n,m,i,j,kk,kkk,p;
double k,l;

while(scanf("%ld %ld",&n,&m)!=EOF){p=1;
if(n==1) {printf("Boring\n");continue;}
else if(m==0 || n==0) {printf("Boring!\n");continue;}


if(n>1 && m==1){
kkk=sqrt(n);
for(i=2;i<=kkk;i++){
for(j=2;j<=31;j++){
if(pow(i,j)==n){ p=0;break;}
else if(pow(i,j)>n) break;

}
if(p==0) break;
}
if(p==0){
for(;j>=0;j--){kk=pow(i,j); printf("%ld ",kk);}
printf("\n");
}
else printf("Boring!\n");
continue;







}





for(i=1;;i++) {
k=pow(m,i);
if(k==n) {
for(j=i;j>=0;j--) {kk=pow(m,j);printf("%ld ",kk);}
printf("\n");break;
}
else if(k>n) {printf("Boring!\n");break;}
}

}
return 0;
}
aaa
Post Reply

Return to “Volume 101 (10100-10199)”