hdoj 1098 Ignatius's puzzle

来源:互联网 发布:淘宝追加好评长心吗 编辑:程序博客网 时间:2024/06/11 18:22

Ignatius's puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7082    Accepted Submission(s): 4891


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
111009999
 

Sample Output
22no43
 

利用数学归纳法和多项式的知识:

假设x=1时成立,那么。。。

假设x=n时成立,那么有。。。

接下来只需证明x=n+1时成立即可,f(x+1)=5*( ... + ... + ... 每一项都有13 )+13*(...+ ...+ .. 每一项都有5)+ k*a*(x+1)

前面两项都能整除65,所以只需后一项能整除即可。

则有18+k*a  整除65。显而易见(18+k*a)%65==0 该式子65一循环,因此只需遍历1到65即可。

 

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



 

0 0
原创粉丝点击