hdu 1098 Ignatius's puzzle

Ignatius's puzzle

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


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(1)被65整除的a

②假设f(x)能被65整除

③证明f(x+1)也能

利用二项式定理,将f(x+1)展开

f(x+1)=5*( (C13,0)*x^13+(C13,1)*x^12+(C13,2)*x^11+...+(C13,13) )+13*( (C5,0)*x^5+(C5,1)*x^4+(C5,2)*x^3+...+(C5,5) )+k*a*(x+1)

          =f(x)+5*( (C13,1)*x^12+(C13,2)*x^11+...+(C13,13) )+13*( (C5,1)*x^4+(C5,2)*x^3+...+(C5,5) )+k*a*1

因为划线部分都能被65整除,所以只要看5*(C13,13)+13*(C5,5)+k*a(即18+a*k)能否被65整除即可,发现f(1)也等于18+a*k


当k%65=0时,18+k*a是永远除不尽65的

当k%65!=0 时,从1开始找a,判断18+k*a是否能除尽65,找到即止,当a==66时,也就是已经找了一个周期了,在找下去也找不到适当的a了。


代码:

#include<iostream>

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int k,a;
    while(cin>>k)
    {
        for(a=1;a<=65;a++)
        {
            if((18+a*k)%65==0)
            {
                cout<<a<<endl;
                break;
            }
        }
        if(a==66)
            cout<<"no"<<endl;
    }
    return 0;

}

注:

题中65|f(x)是f(x)能被65整除的意思



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值