数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)
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 (费马小定理+打表)的更多相关文章
- 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 因为 ...
- hdu 4704 Sum(组合,费马小定理,快速幂)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4704: 这个题很刁是不是,一点都不6,为什么数据范围要开这么大,把我吓哭了,我kao......说笑的, ...
- HDU 4704 Sum (隔板原理 + 费马小定理)
Sum Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/131072K (Java/Other) Total Submiss ...
- hdu 4704 Sum【组合数学/费马小定理/大数取模】By cellur925
首先,我们珂以抽象出S函数的模型:把n拆成k个正整数,有多少种方案? 答案是C(n-1,k-1). 然后发现我们要求的是一段连续的函数值,仔细思考,并根据组合数的性质,我们珂以发现实际上答案就是在让求 ...
- 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum
Sum Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
- hdu 4704(费马小定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704 思路:一道整数划分题目,不难推出公式:2^(n-1),根据费马小定理:(2,MOD)互质,则2^ ...
- HDU 5667 Sequence【矩阵快速幂+费马小定理】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...
随机推荐
- Linux网络篇,ssh原理及应用
一.对称加密与非对称加密 对称加密: 加密和解密的秘钥使用的是同一个. 非对称加密: 非对称加密算法需要两个密钥:公开密钥(publickey)和私有密钥:简称公钥和私钥 对称加密 对称加密的密 ...
- jQuery extend()和jQuery.fn.extend()区别和详解
1.认识jQuery extend()和jQuery.fn.extend() jQuery的API手册中,extend方法挂载在jQuery和jQuery.fn两个不同对象上方法,但在jQuery内部 ...
- "五号标题"组件:<h5> —— 快应用组件库H-UI
 <import name="h5" src="../Common/ui/h-ui/text/c_h5"></import> < ...
- N皇后问题 回溯非递归算法 C++实现2
运行结果 代码如下 #include <bits/stdc++.h> using namespace std; ; const char *LINE32 = "--------- ...
- flutter和react native如何选择
[关于性能]跨平台开发第一个考虑的就是性能问题RN的效率由于是将View编译成了原生View,所以效率上要比基于Cordova的HTML5高很多,但是它也有效率问题,RN的渲染机制是基于前端框架的考虑 ...
- PHP函数:debug_backtrace
debug_backtrace() - 产生一条 PHP 的回溯跟踪(backtrace). 说明: debug_backtrace ([ int $options = DEBUG_BACKTRAC ...
- vue2.x学习笔记(六)
接着前面的内容:https://www.cnblogs.com/yanggb/p/12571171.html. class与style绑定 操作元素的class列表和内联样式,是数据绑定的一个常见需求 ...
- [WEB前置技能]HTTP协议
HTTP概述 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...
- Redis 5.0.9 安装
目录 系统环境 系统版本 内核版本 安装步骤 安装 gcc 依赖 下载 Redis 解压 Redis 切换到 redis 解压目录下,执行编译 指定目录安装 启动 Redis 服务 最后 系统环境 系 ...
- spark中的pair rdd,看这一篇就够了
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是spark专题的第四篇文章,我们一起来看下Pair RDD. 定义 在之前的文章当中,我们已经熟悉了RDD的相关概念,也了解了RDD基 ...