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. 薅羊毛? 月入10万? | 这是自动化测试老司机的特长--Python自动化带你薅视频红包,一个都不放过!

    一.目标场景 如今短视频横行的时代,以某短视频为首的,背后依靠着强大的资金后盾,疯狂地对平台用户进行红包轰炸. ​ 与传统的红包不一样,视频红包包含位置的不确定性.大小不确定性.元素 ID 的不确定性 ...

  2. Powershell 输出信息过多,结尾显示省略号

    有时候我们通过powershell指令去查询某些信息时,因为输出结果过多,导致一部分重要信息被省略号代替,如下图 面对这种情况无论是 |fl 还是  out-file 亦或是 export-csv都无 ...

  3. MySQL锁---InnoDB行锁需要注意的细节

    前言 换了工作之后,接近半年没有发博客了(一直加班),emmmm.....今天好不容易有时间,记录下工作中遇到的一些问题,接下来应该重拾知识点了.因为新公司工作中MySQL库经常出现查询慢,锁等待,节 ...

  4. Java正则表达式基础知识及实例说明

    众所周知,在程序开发中,难免会遇到需要匹配.查找.替换.判断字符串的情况发生,而这些情况有时又比较复杂,如果用纯编码方式解决,往往会浪费程序员的时间及精力.因此,学习及使用正则表达式,便成了解决这一矛 ...

  5. Ansible简明教程

    Ansible是当下比较流行的自动化运维工具,可通过SSH协议对远程服务器进行集中化的配置管理.应用部署等,常结合Jenkins来实现自动化部署. 除了Ansible,还有像SaltStack.Fab ...

  6. sudo -s 命令 [oh-my-zsh] 提示检测到不安全目录

    运行sudo -s 命令时,[oh-my-zsh] 冒出下面一大堆提示: [oh-my-zsh] Insecure completion-dependent directories detected: ...

  7. testNG 常用的注解

    常用注解介绍: @BeforeSuite 在该套件的所有测试都运行在注释的方法之前,仅运行一次 @AftereSuite 在该套件的所有测试都运行在注释方法之后,仅运行一次 @BeforeClass  ...

  8. JavaScript之预编译

    javascript是一种解释性弱类型语言,在浏览器中执行时,浏览器会先预览某段代码进行语法分析,检查语法的正确与否,然后再进行预编译,到最后才会从上往下一句一句开始执行这段代码,简单得来说可以表示为 ...

  9. TensorFlow命令行参数FLAGS使用

    import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf #tensorboard --logdir=&qu ...

  10. MySQL server has gone away(在执行sql的时候,莫名的报错)

    原文:https://cenalulu.github.io/mysql/mysql-has-gone-away/ MySQL Server has gone away报错原因汇总分析 原因1. MyS ...