Problem Description
Ignatius is poor at math,he falls across a puzzle problem,so he has 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 nonegative integer a,make the arbitrary integer x ,65|f(x)if
no exists that a,then print "no".
no exists that a,then print "no".
Input
The input contains several test cases. Each test case consists of a nonegative integer k, More details in the Sample Input.
Output
The 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
11 100 9999
Sample Output
22 no 43
Author
eddy
分析如下:
只需验证x=1的时候成立即可,HDOJ上面的讨论区证明的很好,
对于为什么只验证x=1成立就能满足条件的证明如下:
因为 ( 5x^13+13x^5+kax )%65==0那么 5(x+1)^13+13(x+1)^5+ka(x+1)中间的二项式展开,其实都是65 的倍数,所以要想这个式子也成立, 那么它展开后必须满足(5+13+ka)%65==0,所以用x=1成立时,对任意的整数就都成立了。
对于给定范围的a只需要验证,是否存在一个a使得(18+k*a)%65==0。
a的范围从1到65,a=66时候开始出现循环。
代码如下:
#include <stdio.h>
int main()
{
int k;
int i;
while(scanf("%d",&k)!=EOF)
{
for(i=1;i<=65;i++)
{
if((18+k*i)%65==0)
{
printf("%d\n",i);
break;
}
}
if(i==66)printf("no\n");
}
return 0;
}