## 10190 - Divide, But Not Quite Conquer!

Moderator: Board moderators

Derk
New poster
Posts: 23
Joined: Mon Mar 17, 2003 3:53 am
Location: Louisville, KY
Contact:

### WA. works for all kinds of test inputs

I can't find my error here.. I've tried all inputs I could think of...

Here's my code and the test I/O I'm using...

[c] int m,n;

while(scanf("%d %d", &n, &m)==2)
{
if (m>n || m == 0 || n == 0)
printf("Boring!\n");
else if (m==n && m != 1)
printf("%d 1\n", m);
else if (m==n && m == 1)
printf("Boring!\n");
else
if(!((float)(log(n)/log(m)) == (float)(int)(log(n)/log(m))) )
printf("Boring!\n");
else
{
while(n!=1)
{
printf("%d ", n);
n=n/m;
}
printf("1\n");
}
}[/c]

And my input:

Code: Select all

``````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 88
88 1
1 1``````
And the output:

Code: Select all

``````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!``````
Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Contact:

### 10190 - Pls help

hi,

this is my code:
[cpp]
#include<iostream.h>

#define MAX 100

main(void)
{
unsigned long long a[MAX],m;
int i,t;

while(cin >> a[0] >> m)
{
i=0;
t=1;
while(a!=1)
{
if(a % m)
{
t = 0;
break;
}

i++;
m = (unsigned long long)(a[i-1]/m);
a = m;
if(!(a[i-1]>a))
{
t = 0;
break;
}
}
if(t)
for(m=0;m<=i;m++)
cout << a[m] << " ";
else
cout << "Boring!";
cout << endl;
}
return 0;
}[/cpp]

this is getting Runtime error
Your program has died with signal 8 (SIGFPE). Meaning:

Floating point exception

Before crash, it ran during 0.000 seconds.

Pls tell me what is the error.

M H Rasel
CUET Old Sailor
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia
SIGFPE most oftenly occurs when there's a division by zero performed during the program execution.
The input will consist on an arbitrary number of lines. Each line will consist of two non-negative integers n,m which are both less than 2000000000. You must read until you reach the end of file.
You program can't handle the input where m is zero (since zero is also non negative integer). In the case where m is zero, there will be a division by zero and thus produce SIGFPE!!
Hope it helps!!
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.
Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Contact:
Thanks a lot.
I will try with this way.

M H Rasel
CUET Old Sailor
Dmytro Chernysh
Experienced poster
Posts: 146
Joined: Sat Apr 26, 2003 2:51 am
I can give you input/output...
Mail me.
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

### 10190 WA :(

I have tested he code for all inputs i could think of. I would be great if any of u guys could tell me what is wrong with the code or just tell me the test case where it fails...

I use log to check if it is a power or not and then start dividing......

[cpp]
# include<iostream.h>
# include<math.h>

long long a,n;
double x;

int main()
{
while(cin>>a>>n)
{
if(a<=1 || n<=1) {cout<<"Boring!\n";continue;}

x=log(a)/log(n);

if(fabs(x-int(x))<=1e-7)
{
do
{
cout<<a<<" ";
a/=n;
}
while(a!=1);
cout<<1<<"\n";
}
else
{
cout<<"Boring!\n";
}
}
return 1;
}
[/cpp]
...I was born to code...
Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Contact:
Get AC.

Thanks all of you.

M H Rasel
CUET Old Sailor.
Amir Aavani
New poster
Posts: 30
Joined: Wed Oct 23, 2002 6:53 am
may be your problem is in log function ( i mean that floating point error). why you don't devide a by n in your while and check if new a is a devisor of n.
something like this:
i:= 0;
while (a mod n= 0) do
begin
Inc (i);
No := a div n;
a:= a div n;
end;
if a= 1 then
for i:= 1 to i do
Write (No )
else
Write ('boaring');
Examiner
New poster
Posts: 28
Joined: Thu Feb 19, 2004 1:19 pm
Why is the answer "Boring!" but not "1", when n = 1 and 0 ≤ m < 2,000,000,000? Can't k be 1?
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
It says in the restrictions that k > 1.
Examiner
New poster
Posts: 28
Joined: Thu Feb 19, 2004 1:19 pm
Do you refer to this line?
a[1] = n, a = a[i-1] div m, for all 1 < i <= k

Now I understand what you mean. I interpreted the inequality "1 < i ≤ k" as only a restriction on i. When k ≤ 1, this inequlity never holds, so the quoted statement is always satisfied. But you think the statement is also a restriction on k.

What's in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.
Alan J. Perlis
kami
New poster
Posts: 2
Joined: Sat May 15, 2004 10:04 pm

### 10190 Runtime Error:(acc)

what is the problem in this code any one help me
giving me runtime error

code
Last edited by kami on Tue Jun 15, 2004 9:08 pm, edited 2 times in total.
yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:
a[1] = n, a = a[i-1] div m, for all 1 < i <= k

why/how would that imply k>1?

that statement is the same as
a[1]=n, a=a[i-1] div m, for all 1<i AND i<=k

so when k is 1, you got
a[1]=n, a=a[i-1] div m, for all 1<i AND i<=1,

all it means is there is not such integer i.
and the statement is true.

Say we have
For all x in S, f(x).

if S is Empty Set, then statement is true, right?
gits
New poster
Posts: 19
Joined: Sun Oct 26, 2003 10:08 pm
Location: Aveiro, Portugal
Contact:
yiuyuho, I totally agree with you. However, in my first submission I produced output "1" for input "1 1" and got WA, then changed it to "Boring!" and it was accepted.

So k must be > 1, but the description isn't very accurate.
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

### 10190-need I/O For Test

Hi All Solver
I need Some Data For 10190
I test it with all possible condition BUT i get WA all Time
Can any body help me

ROCKY