10831  Gerg's Cake
Moderator: Board moderators
10831  Gerg's Cake
Can somebody give hint how to solve this poblem?
Thanks
Thanks
someone who like to solve informatic problems.
http://acm.uva.es/cgibin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgibin/OnlineJudge?AuthorInfo:29650

 Guru
 Posts: 647
 Joined: Wed Jun 26, 2002 10:12 pm
 Location: Hong Kong and New York City
 Contact:
Here are my inputs and outputs, is there anything wrong?
Code: Select all
1 3
1024 17
2 101
0 1
3000000000 5
15 11
721761 7
115 2
6137 2
4 2
0 2
1 1
Code: Select all
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Check out http://www.algorithmist.com !
Hello!
Only one question?
Could anyone say me what is wrong in my code?
Any test cases will be appreciated.
Thnaks!
Only one question?
Could anyone say me what is wrong in my code?
Code: Select all
#include <iostream>
using namespace std;
main ()
{
long long a, p, x, sq;
while (cin >> a >> p && (a!=1  p!=1))
{
x=a%p;
sq=0;
while (sq*sq<x) sq++;
if (sq*sq==x) cout << "Yes\n";
else cout << "No\n";
}
}
Thnaks!
Here are some test cases. My program prints "Yes" to all of them.
Code: Select all
2 7
9 7
16 7
3 11
5 11
31337 2147483629
2147483628 2147483629
1 1
Hello and thanks mf!
I have used Legendre's symbol, and get correct output for all the input of this thread.
Maybe I haven't computed right Legendre's symbol.
If someone can explain me a bit how have computed this to solve the problem, I will be happy
By other hand I have here some test cases, if someone can say if the output is correct I will be happy too
input:
output:
I have used Legendre's symbol, and get correct output for all the input of this thread.
Maybe I haven't computed right Legendre's symbol.
If someone can explain me a bit how have computed this to solve the problem, I will be happy
By other hand I have here some test cases, if someone can say if the output is correct I will be happy too
input:
Code: Select all
2 7
9 7
16 7
3 11
5 11
31337 2147483629
2147483628 2147483629
1 3
1024 17
2 101
0 1
300000000 5
15 11
721761 7
115 2
6137 2
4 2
0 2
3 2
5 2
2 3
2 5
2 2
234 23
234 31
485940 101
2384 101
3843 101
3848 41
3848 31
48885557 31
31 41
347583495 7
23477767 23
347823 101
3478234 2147483629
115 3
115 2
3478293 17
2348884 19
1234123 17
1234123 19
1234123 23
1 1
Code: Select all
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
Yes
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes

 A great helper
 Posts: 481
 Joined: Sun Jun 19, 2005 1:18 am
 Location: European Union (Slovak Republic)
The answer for a=31, b=41 should be Yes. (32nd case)Emilio wrote:Hello and thanks mf!
I have used Legendre's symbol, and get correct output for all the input of this thread.
Maybe I haven't computed right Legendre's symbol.
If someone can explain me a bit how have computed this to solve the problem, I will be happy
By other hand I have here some test cases, if someone can say if the output is correct I will be happy too
Thanks Martin Macko!
I got AC.
I had a small bug at my algorithm. But one question, I have obtained a time of 0:00.535, and most of solvers have obtained a time about 0:00.030 or smaller, I would like know the method used. I used a method that is about Legendre's symbol and law of quadratic reciprocity, in this method I must break down a number in his prime numbers, and make transformations to obtain trivial cases that I can solve directly.
Any other hint or method will be highlyregarded.
I got AC.
I had a small bug at my algorithm. But one question, I have obtained a time of 0:00.535, and most of solvers have obtained a time about 0:00.030 or smaller, I would like know the method used. I used a method that is about Legendre's symbol and law of quadratic reciprocity, in this method I must break down a number in his prime numbers, and make transformations to obtain trivial cases that I can solve directly.
Any other hint or method will be highlyregarded.
Legendre symbol can be computed as a^((p1)/2) (mod p). It's just modular exponentiation.
My 0.002s solution is based on an algorithm from http://www.cacr.math.uwaterloo.ca/hac/about/chap2.pdf page 27, algorithm #2.149.
My 0.002s solution is based on an algorithm from http://www.cacr.math.uwaterloo.ca/hac/about/chap2.pdf page 27, algorithm #2.149.
Re: 10831  Gerg’s Cake
Posted an ac code. So deleted.
Last edited by Masum on Fri Dec 27, 2013 3:24 am, edited 1 time in total.

 Guru
 Posts: 5947
 Joined: Thu Sep 01, 2011 9:09 am
 Location: San Jose, CA, USA
Re: 10831  Gerg’s Cake
That is AC code and input 31 41 should output Yes
Check input and AC output for thousands of problems on uDebug!