Couple doubi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 313 Accepted Submission(s): 251
Problem Description
DouBiXp 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 balls 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 balls in turn and DouBiNan first. After all the balls are token, they compare the sum of values with the other ,and the person who get larger sum will win the game. You should print “YES” if DouBiNan will win the game. Otherwise you should print “NO”.
Input
Multiply Test Cases.
In the first line there are two Integers k and p(1<k,p<2^31).
In the first line there are two Integers k and p(1<k,p<2^31).
Output
For each line, output an integer, as described above.
Sample Input
2 3 20 3
Sample Output
YES NO
Author
FZU
Source
2014 Multi-University Training Contest 1
题意:n个球,每个球的价值1^i+2^i+...+(p-1)^i (mod p) ; 轮流取球,问最后谁的总和大
#include <cstdio>
#define max 1e
int f(int i,int j,int p)
{
int num = 1, k ;
for(k = 1 ; k <= i ; k++)
{
num *= j ;
num %= p ;
}
return num ;
}
int main()
{
int a , p , num , i , j , sum , temp ;
for(a = 2 ; a <= 10 ; a++)
{
for(p = 2 ; p <= 10 ; p++)
{
if(p ==2 || p == 3 || p == 5 || p== 7)
;
else
continue ;
printf("n == %d p == %d\n", a, p);
temp = 0 ;
for(i = 1 ; i <= a ; i++)
{
sum = 0 ;
for(j = 1 ; j < p ; j++)
{
sum += f(i,j,p);
}
sum %= p ;
if(sum)
temp++ ;
printf("%d ", sum);
}
printf("\n");
}
}
}
跑了10*(2,3,5,7)后的出,n个球的值 第(k*(p-1))个球的值为(p-1),其余的均为0 ;
#include <cstdio>
int main()
{
int n , p ;
while(scanf("%d %d", &n, &p)!=EOF)
{
if( (n/(p-1))%2 )
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
解题报道:费马小定理。。。。。。sad