HDU 1098 Ignatius's puzzle 二项式定理

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".
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
 
规律:
若f(x)都能被65整除.推断出:f(x+1)|65也成立.

f(x+1)=5*(x+1)^13+13*(x+1)^5+k*a*(x+1),

根据二项式定理:(a+b)^n=C(n,0)a^n+C(n,1)a^(n-1)*b+C(n,2)a^(n-2)*b^2+...+C(n,n)b^n

得:f(x+1)=5*(C(13,0)+C(13,1)*x+C(13,2)*x^2+...+C(13,13)*x^13) + 13*(C(5,0)+C(5,1)*x+...+C(5,5)*x^5) + k*a*(x+1);

 从中提取出f(x)后得:

f(x+1)=f(x)+5*(C(13,0) + C(13,1)*x+C(13,2)*x^2+...+C(13,12)*x^12) + 13*(C(5,0)+C(5,1)*x+...+C(5,4)*x^4) + k*a;

 不难看出出了5*C(13,0) 、13*C(5,0)和k*a三项以外,其他项无论x取任意整数都能被65整除,所以

如果5*C(13,0) +13*C(5,0)+k*a(相当于18+k*a)能被65整除的话,就可以得出f(x+1)|65了。

code:

View Code
#include<stdio.h>
int main()
{
int k,a,i;
while(scanf("%d",&k)!=EOF)
{
if(k%65==0)
printf("no\n");
else
{
for(a=1;a<65;a++)
if((18+k*a)%65==0)
{printf("%d\n",a);
break;}
if(a==65)
printf("no\n");
}
}
return 0;
}



posted @ 2012-04-06 16:49  'wind  阅读(206)  评论(0编辑  收藏  举报