Ignatius ' s puzzleTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 7012 Accepted Submission (s): 4847
Problem Descriptionignatius is poor at Math,he falls across a puzzle problem,so he have no choice but to appeal to Eddy. This problem describes that:f (x) =5*x^13+13*x^5+k*a*x,input a nonegative integer k (k<10000), to find the minimal Nonegat Ive integer a,make The arbitrary integer x, 65|f (x) if
No exists that a,then print "no".
Inputthe input contains several test cases. Each test case consists of a nonegative an integer k, more details in the Sample Input.
Outputthe output contains a string "No" if you can ' t find a,or you should output a line contains the A.more details in the Sample Output.
Sample Input
111009999
Sample Output
22no43
Authoreddy
Article reference: Click to open the link
F (x) =5*x^13+13*x^5+k*a*x=x (5*x^12+13*x^4+k*a), the form of this function is directly the form of the Fermat theorem
Fermat theorem (Fermat theory) is an important theorem in number theory: if P is prime, and gcd (a,p) = 1, then a (p-1) ≡1 (mod p). That is: If A is an integer, p is a prime number, and A,p coprime (that is, there is only one convention of 1), then the remainder of a (p-1) divided by P is constant equal to 1.
The four theorems of number theory: Baidu Encyclopedia (Proof of Fermat theorem)
The f (x) =x (5*x^12+13*x^4+k*a) is analyzed with this theorem:
(1) If x is a multiple of 65, then it is already 65 divisible by F (x)
(2) If X is a multiple of 5, as long as the 5*x^12+13*x^4+k*a is divisible by 13, remove the multiples of 13 13*x^4, that is, 5*x^12+k*a is divisible by 13, by the Fermat theorem, 5 and 13 coprime, 13 is prime, so x^ (13-1) modulo 13 1, so 5 *x^12 die 13 More than 5, to make 5*x^12+k*a by 13 divisible, k*a must die 13 8 (k*a≡8 (mod 13))
(3) If X is a multiple of 13, similar to (2), need 13*x^4+k*a is divisible by 5, similar to the Fermat theorem to get the x^4 die 5 1, so 13*x^4 die 5 3,k*a Must Die 5 2 (k*a≡2 (mod 5))
(4) If X does not contain 5 and 13 of these two factors, it is necessary to 5*x^12+13*x^4+k*a be 65 integer, equivalent to both by 5 and divisible by 13, equivalent to the above (2) (3) conditions to be satisfied at the same time, so there are k*a≡2 (mod 5) and k*a≡8 ( MoD 13)
because the title says that for any x 65 can divide the F (x), so k*a≡2 (mod 5) and k*a≡8 (mod 13) need to be set up at the same time.
AC Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int Main () {int k;while (scanf ("%d", &k)! = EOF) {int flag = 0;for (int i = 1; i <=; i++) {if (i * k% 13 = = 8 && I * k% 5 ==2) {printf ("%d\n", i); flag = 1;break;}} if (flag = = 0) printf ("no\n");} return 0;}
Hdu-1098-ignatius ' s puzzle (number theory-Fermat theorem)