Address: couple doubi
Question:
There are K balls on the table, with the formula every ball has a value and the value of ith (I = ,..., k) Ball is 1 ^ I + 2 ^ I +... + (p-1) ^ I (mod P ). P is a prime number (3.5.7 ....). Doubinan and doubixp, each person takes one ball in turn to calculate the sum of the values of the ball to compare who wins. Nan first gets if win output yes otherwise no.
Solution:
Find the rule and list the winning and losing situations where p is 3 and K is 1-10, and P is 5, K is 1-10, and P is 7, and K is 1-10.
The result of P = 3 is found to be (0202020202) P = 5 (00040004) P = 7 (five zeros and a number ). Therefore, it is easy to find the rules by writing yes and no.
Assume that the winning and losing situations of P = 7, k <= 6 are all no, and K> = 7 is a loop of 7 groups.
Code:
1 # include <algorithm> 2 # include <iostream> 3 # include <sstream> 4 # include <cstdlib> 5 # include <cstring> 6 # include <cstdio> 7 # include <string> 8 # include <bitset> 9 # include <vector> 10 # include <queue> 11 # include <stack> 12 # include <cmath> 13 # include <list> 14/ /# include <map> 15 # include <set> 16 using namespace STD; 17 /************************************** */18 # define ll long long19 # define in T64 _ int6420 # define PI 3.141592721 /******************************* * ******/22 const int INF = 0x7f7f7f7f; 23 const double EPS = 1e-8; 24 const double PIE = ACOs (-1.0); 25 const int d1x [] = {0,-, 1 }; 26 const int d1y [] = {-,}; 27 const int d2x [] = {0,-, 1}; 28 const int d2y [] =, -}; 29 const int FX [] = {-1,-1,-,}; 30 const int FY [] = {-, 1, -,-, 1}; 31 const int dirx [] = {-,-2, 2,-,-}; 32 const int diry [] = {-2,-2,-1,-, 2 }; 33/* vector <int> map [N]; Map [A]. push_back (B); int Len = map [v]. size (); */34 /************************************ ***/35 void openfile () 36 {37 freopen ("data. in "," rb ", stdin); 38 freopen (" data. out "," WB ", stdout); 39} 40 priority_queue <int> qi1; 41 priority_queue <int, vector <int>, greater <int> qi2; 42/*********************** Lili split line, the above is the template section **************** */43 44 int main () 45 {46 int K, P; 47 While (scanf ("% d", & K, & P )! = EOF) 48 {49 int sum1 = P-2, sum2; 50 if (k <= sum1) 51 {52 printf ("NO \ n "); 53} 54 else55 {56 sum2 = K/(sum1 + 1); 57 if (sum2% 2) 58 printf ("Yes \ n "); 59 else60 printf ("NO \ n"); 61} 62} 63 return 0; 64}
View code