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)=5x13+13*x5+ka*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

Author

eddy

Recommend

We have carefully selected several similar problems for you: 1071 1014 1052 1097 1082

题目大意:

给定一个k,找到最小的a 使得 f(x)=5x13+13*x5+ka*x ,f(x)%65永远等于0

打表的话就很明显的看导规律

也可以用费马小定理证明

#include <iostream>
#include <cstdio>
using namespace std;
int gcd(int a, int b)
{
if (a < b)
return gcd(b, a);
if (b == 0)
return a;
if ((a & 1) == 0 && (b & 1) == 0)
return 2 * gcd(a >> 1, b >> 1); //a and b are even
if ((a & 1) == 0)
return gcd(a >> 1, b); // only a is even
if ((b & 1) == 0)
return gcd(a, b >> 1); // only b is even
return gcd((a + b) >> 1, (a - b) >> 1); // a and b are odd
}
int main()
{
int k;
while (scanf("%d", &k) != EOF)
{
if (18 % gcd(k, 65) == 0)
{
for (int a = 0;; a++)
{
if ((18 + k * a) % 65 == 0)
{
printf("%d\n", a);
break;
}
}
}
else
printf("no\n");
}
return 0;
}

数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)的更多相关文章

  1. HDU 1098 Ignatius's puzzle 费马小定理+扩展欧几里德算法

    题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为 ...

  2. hdu 4704 Sum(组合,费马小定理,快速幂)

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4704: 这个题很刁是不是,一点都不6,为什么数据范围要开这么大,把我吓哭了,我kao......说笑的, ...

  3. HDU 4704 Sum (隔板原理 + 费马小定理)

    Sum Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/131072K (Java/Other) Total Submiss ...

  4. hdu 4704 Sum【组合数学/费马小定理/大数取模】By cellur925

    首先,我们珂以抽象出S函数的模型:把n拆成k个正整数,有多少种方案? 答案是C(n-1,k-1). 然后发现我们要求的是一段连续的函数值,仔细思考,并根据组合数的性质,我们珂以发现实际上答案就是在让求 ...

  5. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  6. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

  7. HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description   Sample Input 2 Sample Outp ...

  8. hdu 4704(费马小定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704 思路:一道整数划分题目,不难推出公式:2^(n-1),根据费马小定理:(2,MOD)互质,则2^ ...

  9. HDU 5667 Sequence【矩阵快速幂+费马小定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...

随机推荐

  1. 深入理解equals和hashCode关系和区别

    为什么要说equals和hashCode这两个东西,一来是因为有不少小伙伴面试时被问过这个东西,二来则是因为如果了解了这两个东西的原理,那么实际的开发过程中,对效率和容错率上还是能帮上很大的忙! 直入 ...

  2. python3(六) for while

    # Python的循环有两种,一种是for...in循环,依次把list或tuple中的每个元素迭代出来 names = ['Michael', 'Bob', 'Tracy'] for name in ...

  3. 跳转语句break与continue的使用环境

    break:改变程序控制流 常用于do-while.while.for .switch循环中,终止某个循环,程序跳转到循环块外的下一条语句 continue:跳出本次循环,进入下一次循环

  4. 这价格看得我偷偷摸了泪——用python爬取北京二手房数据

    如果想了解更多关于python的应用,可以私信我,或者加群,里面到资料都是免费的 http://t.cn/A6Zvjdun 近期,有个朋友联系我,想统计一下北京二手房的相关的数据,而自己用Excel统 ...

  5. C - Ekka Dokka

    Ekka and his friend Dokka decided to buy a cake. They both love cakes and that's why they want to sh ...

  6. JavaScript中的作用域和作用域链(边学边写)[看着别人的博客纯手敲]

    作用域是JavaScript最重要的概念之一,想要学好JavaScript就需要理解JavaScript作用域和作用域的工作原理.今天这篇文章对JavaScript作用域和作用域链简单的介绍,希望能帮 ...

  7. python第三方库安装与卸载

    一.检查python环境是否正常 python安装完毕并设置环境变量后,可在cmd中运行python查看,显示版本等信息  二.查看已经安装的第三方库 通过pip list可查看已安装的库,以及对应的 ...

  8. GitHub 热点速览 Vol.17:在?各家视频会员要不要?

    作者:HelloGitHub-小鱼干 摘要:经济实用,用作上周的 GitHub 热点的横批再合适不过.先不说 GitHub Trending 上不止一个的会员共享项目,免你找好友刷脸要会员,这项目实在 ...

  9. jquery选择时分插件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. sql注入notebook

    内容来自: https://ca0y1h.top/ 联合查询注入 使用场景 页面上有显示位 什么是显示位:在一个在一个网站的正常页面,服务端执行SQL语句查询数据库中的数据,客户端将数据展示在页面中, ...