You can use the table to find the rule over the problem. But this is obviously not the original intention of the problem.
Test instructions is very simple actually is to judge var = (1^i + 2^i + ... + (p-1) ^i) (mod p)//Important initial condition: P is prime number
First you must know the Fermat theorem.
If P is prime and p does not divide a so a^ (p-1) ≡1 (mod p) < because I don't have a good math formula editor on my side. I can only use words to describe something >
We found that the subscript value of the above Var is from P-1 to meet the above requirements for a.
So when (p-1) |i is (p-1) divisible I set up, then each small formula value is 11 total p-1 formula, so var = p-1
The difficulty of this problem is to find out (p-1) and I do not divide the relationship between the value of Var is how much
This is going to involve a mathematical concept: the original root
In a^ (x) ≡1 (mod p), if the minimum number of x is P-1 then A is called the original root of modulo p. < each prime number p is by the original root, to be exact, each prime number p has an F (p-1) The original root of the P (s) >
The f (z) function on this side is the Euler function, which can be proved. I'm not writing this, because I think this proves to be quite a nuisance.
For the original root g of modulo p
The value of g^1,g^2,g^3....g^ (p-1) mod p corresponds to the order of the 1,2,3....p-1 in different orders
Let's prove its correctness.
Suppose G^i≡g^j (mod p) so the P is divisible (G^I-G^J)//This side assumes i>=j this is not related because I j inevitably exists a size relationship of course you can say j>=i
p| (G^I-G^J), p| (G^j * (g^ (I-J)-1) because GCD (p, g^j) = 1 then p|g^ (i-j)-1 that means
g^ (i-j)-1 = k*p+1 (k=0,1,2,3,....) that is g^ (i-j) ≡1 (mod p) < see here if you think of Fermat theorem >
Now let's overturn our assumptions.
1<=j<=i<=p-1-0<=i-j<=p-2 so want to let g^ (i-j) ≡1 (mod p) to set up can only make i-j=0 so i = = J
So assuming that the error does not exist in different I j to make G^i, G^j has different values for P modulus so the above conclusion is valid.
Then we can do a key conversion step.
var = (1^i + 2^i + ... + (p-1) ^i) (mod p)
var = (g^1^i + g^2^i + .... + g^ (p-1) ^i) (mod p)//This way I'm converting 1^i+2^i+3^i+...+ (p-1) ^i as a whole, because it's a different order, but the middle operator is the plus sign.
var = (g^i^1 + g^i^2 + ...) + g^i^ (p-1) (mod p)//You will be pleasantly surprised to find now that the first term is g^i and the male ratio is also g^i we now find its sequence and
Sn = (g^i) * (g^i^ (p-1))/(1-g^i)
sn = (g^i) * (g^ (p-1) ^i)/(1-g^i) because g^ (p-1) ≡1 (mod p) so sn = 0
Note that in the (p-1) |i when the mother is 0, it is not possible to carry out equal to sum calculation.
So in the end we just have to think about the parity of the number k/(P-1).
If it's an even-numbered initiator, if it's an odd winner,
The above derivation process may still have some problems forgive = = Sometimes it is not very well expressed. The best message for everyone to discuss the next AH.
1#include <iostream>2 using namespacestd;3 4 intMain ()5 {6 intx, y, ans;7 while(Cin >> x >>y)8 {9Ans = x/(y1);Ten if(ans&1 ) Onecout <<"YES"<<Endl; A Else -cout <<"NO"<<Endl; - } the return 0; -}
View Code
hdu--4861--Fermat theorem && primary root of prime number