10622 - Perfect P-th Powers
Moderator: Board moderators
-
- Learning poster
- Posts: 53
- Joined: Sat Jan 24, 2004 9:22 pm
- Location: Tomsk, Siberia, RUSSIA
- Contact:
10622 - Perfect P-th Powers
Funny, but I was having problems with that task.
Please help me with this:
1. Is magnitude of x the same as |x|?
2. I guess I could use some good tests to find where my program lies to me.
Please help me with this:
1. Is magnitude of x the same as |x|?
2. I guess I could use some good tests to find where my program lies to me.
The more contests are held, the happier I am.
Re: (Something...) Powers. From Waterloo contest.
We needed 18 tries to get it working (yes, i'm a bit trigger happy when i get angryalex[LSD] wrote:Funny, but I was having problems with that task.
Please help me with this:
1. Is magnitude of x the same as |x|?
2. I guess I could use some good tests to find where my program lies to me.
![:D](./images/smilies/icon_biggrin.gif)
1. Yes.
Code: Select all
2147483647
32
-32
64
-64
4
-4
Code: Select all
1
5
5
6
3
2
1
HoraPe
-
- New poster
- Posts: 5
- Joined: Wed Feb 04, 2004 4:58 pm
- Location: Poland, Gliwice
10622 (perfect p-th powers)
I don't get it. I thought this problem is quite easy but I'm still getting wrong answer. What am I doing not in the proper way?
Code: Select all
program p10622(input, output);
var x : cardinal;
procedure check(x : cardinal);
var j : cardinal; i,k,nr,max : cardinal;
begin
max := 1;
for i := 2 to round(sqrt(x)) do if x mod i = 0 then
begin
j := i; nr := 1; k := x div i;
while j < k do
begin
j := j*i;
inc(nr);
end;
if (x div i = j) and (nr >= max) then
begin
max := nr+1;
break;
end;
end;
writeln(output, max);
end;
BEGIN
while true do
begin
readln(input, x);
if x = 0 then break
else check(x);
end;
END.
-
- New poster
- Posts: 39
- Joined: Fri Nov 14, 2003 11:18 pm
- Location: Riga, Latvia
- Contact:
-
- New poster
- Posts: 5
- Joined: Wed Feb 04, 2004 4:58 pm
- Location: Poland, Gliwice
At first I define x as a longint type but i got WA. In the text of the problem is written:
I didn't know that RE is shown as a WA in pascal, so thanks. I've tested the 'check' procedure but I can't find mistake.![:-?](./images/smilies/icon_confused.gif)
Maybe I've omited some important issue?
... so I changed x into a cardinal type but the same error has occured.The value of x will have magnitude at least 2 and be within the range of a (32-bit) int in C, C++, and Java
I didn't know that RE is shown as a WA in pascal, so thanks. I've tested the 'check' procedure but I can't find mistake.
![:-?](./images/smilies/icon_confused.gif)
Maybe I've omited some important issue?
-
- New poster
- Posts: 39
- Joined: Fri Nov 14, 2003 11:18 pm
- Location: Riga, Latvia
- Contact:
-
- New poster
- Posts: 5
- Joined: Wed Feb 04, 2004 4:58 pm
- Location: Poland, Gliwice
You are right. Now I run 'check' with absolute value. I have also considered if x < 0 and p is even - then the procedure returns p=1.
The programme works over 0,5 sec longer. After this time it gives WA.
I used int64 instead of longint but it didn't help.
The programme works over 0,5 sec longer. After this time it gives WA.
I used int64 instead of longint but it didn't help.
Code: Select all
program p10622(input, output);
type int = int64;
var
x : int;
a : longint;
procedure check(x : cardinal);
var i : longint; j,k,nr,max : int;
begin
max := 1;
for i := 2 to round(sqrt(x)) do if x mod i = 0 then
begin
j := i; nr := 1; k := x div i;
while j < k do
begin
j := j*i;
inc(nr);
end;
if (x div i = j) and (nr >= max) then
begin
max := nr+1;
break;
end;
end;
if (a = -1) and not odd(max) then max := 1;
writeln(output, max);
end;
BEGIN
while true do
begin
readln(input, x);
if x < 0 then
begin
a := -1; x := -x;
end
else a := 1;
if x = 0 then break
else if x > 0 then check(x);
end;
END.
-
- New poster
- Posts: 39
- Joined: Fri Nov 14, 2003 11:18 pm
- Location: Riga, Latvia
- Contact:
(the main thing in this edited post was as follows:
)
...it is OK, I believe the answer for, say, -64, to be 3, not 1 (with the current configuration max will be 6, then 1), because -64=(-4)^3.
Good luck!
![:wink:](./images/smilies/icon_wink.gif)
...it is OK, I believe the answer for, say, -64, to be 3, not 1 (with the current configuration max will be 6, then 1), because -64=(-4)^3.
Good luck!
Last edited by Aleksandrs Saveljevs on Thu Feb 05, 2004 1:21 am, edited 1 time in total.
-
- New poster
- Posts: 5
- Joined: Wed Feb 04, 2004 4:58 pm
- Location: Poland, Gliwice
Frustrations---Wanting some helps
What's wrong with my code, I can’t understand. My program produced correct answers of all inputs that I had found. But, Every time get shock when I submit my code. What’s wrong. Has any critical case that I have missed. In the problem statement,
Could anybody tell me something. I gave some inputs and outputs. Could anybody tell me about the correctness of my answers.
Inputs:
14348907
1254874569
-8388608
8388608
65536
-65536
Outputs:
15
1
23
23
16
1
Are my outputs correct? Could somebody give me some critical inputs and outputs.
According to this statement, the value of x will be always positive. Is not it? I considered both positive and negative for the value of x. But wrong answer is not escaping me.The value of x will have magnitude at least 2 and be within the range of a (32-bit) int in C, C++, and Java.
Could anybody tell me something. I gave some inputs and outputs. Could anybody tell me about the correctness of my answers.
Inputs:
14348907
1254874569
-8388608
8388608
65536
-65536
Outputs:
15
1
23
23
16
1
Are my outputs correct? Could somebody give me some critical inputs and outputs.
Not specified
Hello everybody:
Although, i didn't get any good help, but i got accepted after getting a huge amount of wrong answers (
).
Although, i didn't get any good help, but i got accepted after getting a huge amount of wrong answers (
![:evil:](./images/smilies/icon_evil.gif)
![:P](./images/smilies/icon_razz.gif)