2014 Multi-University Training Contest 1/HDU4861_Couple doubi (number theory/law), hdu4861
The problem-solving report shows that the two take the ball in turn, and the big ones win, and post an official question, and, anyway, I don't understand, and, first, keep understanding about the ferma small theorem about the original root.
Find, sad, and the cycle section P-1. Each cycle contains a non-zero ball. Therefore, you only need to determine how many complete cycle sections are found, when determining the parity ,,,
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){ int k,p,i,j; while(scanf("%d%d",&k,&p)!=EOF){ int q=k/(p-1); if(q%2==0) printf("NO\n"); else printf("YES\n"); } return 0;}
Couple doubi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 145 Accepted Submission (s): 122
Problem DescriptionDouBiXp has a girlfriend named DouBiNan. one day they felt very boring and decided to play some games. the rule of this game is as following. there are k bils on the desk. every ball has a value and the value of ith (I = 1, 2 ,..., k) ball is 1 ^ I + 2 ^ I +... + (p-1) ^ I (mod p ). number p is a prime number that is chosen by DouBiXp and his girlfriend. and then they take bils in turn and DouBiNan first. after all the bils are token, they compare the sum of values with the other, and the person who get larger sum will win the game. you shoshould print "YES" if DouBiNan will win the game. otherwise you shoshould print "NO ".
InputMultiply Test Cases.
In the first line there are two Integers k and p (1 <k, p <2 ^ 31 ).
OutputFor each line, output an integer, as described above.
Sample Input
2 320 3
Sample Output
YESNO
Source2014 Multi-University Training Contest 1