杭电 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): 7068    Accepted Submission(s): 4883

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

Author

eddy

题目的关键是函数式f(x)=5*x^13+13*x^5+k*a*x;  
用数学归纳法证明:x取任何值都需要能被65整除..

所以我们只需找到f(1)成立的a,并在假设f(x)成立的基础上,

证明f(x+1)也成立即可。此时经过整理 只要(18+k*a)能够被65整除 ,求最小a的问题。

#include<iostream>
using namespace std;
int main()
{
	int k,a;
	while(cin>>k)
	{
		int i;
		for( i=0;i<66;i++)
 		  if((18+k*i)%65==0)
		  {
			  cout<<i<<endl;
			break;
		  }
		if(i==66)
			cout<<"no"<<endl;
	}
	return 0;
}

杭电 HDU 1098 Ignatius's puzzle

时间: 2024-10-26 01:16:51

杭电 HDU 1098 Ignatius's puzzle的相关文章

HDU 1098 Ignatius&#39;s Puzzle(解法汇集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1098 题意: 求针对输入的k,能否找到一个最小的a,使得当x取任意自然数时,f(x)=5*x^13+13*x^5+k*a*x始终能被65整除. 我的解法: 取f(1),f(2)两个特殊值得. 1.       5+13+k*a=65*T1  ->> k*a=47+65*T3 2.       5*2^13+13*2^5+2*k*a=65*T2  ->>  41376+2*k*a=65*

HDU 1098 Ignatius&#39;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 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

HDU 1098 Ignatius&#39;s puzzle 也不大懂

http://acm.hdu.edu.cn/showproblem.php?pid=1098 看了一下它们的思路,没完全明白,但是能写出来,大概可能也许就是这样做的吧. 1 #include <iostream> 2 using namespace std; 3 typedef long long ll; 4 5 int main() { 6 ll k; 7 while (cin>>k) 8 { 9 int flag = 0,a; 10 for ( a = 1; a <= 6

HDU - 1098 - Ignatius&#39;s puzzle (数论 - 费马小定理)

Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7012    Accepted Submission(s): 4847 Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no

HDU 1098 Ignatius&#39;s puzzle

这题刚开始看的时候,的确被吓了一跳,13次方,这也太大了,而且还是任意的x,有点麻烦,但是仔细分析之后,发现有点窍门: 65|f(x),不妨设5*x^13+13*x^5+k*a*x=m*65,于是可以得到: x*(5*x^12+13*x^4+k*a)=m*65,继续得到: x*(5*x^12+13*x^4+k*a)/65=m,因为是对于任意的x均成立,所以(5*x^12+13*x^4+k*a)/65=n是成立的,这个式子为什么是成立的呢?首先k*a的值是确定的,所以要想被65整除,那么(5*x^

HDU 1098 [Ignatius&#39;s puzzle] 数论

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1098 题目大意:f(x)=5x^13+13x^5+kax. 给出k,求a使得对任意x,满足f(x)是65的倍数 关键思想:f(x)要是65的倍数,需满足f(x)既是5的倍数又是13的倍数. 1.f(x)为5的倍数需满足  f(x) % 5 = 0 5x^13+13x^5+kax % 5 = 0  x(13x^4+ka) % 5 = 0  对任意x成立    13+ka % 5 = 0  //费马小定

HDU 1098 Ignatius&#39;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)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal

HDU - 1098 - Ignatius&#39;s puzzle - ax+by=c

http://acm.hdu.edu.cn/showproblem.php?pid=1098 其实一开始猜测只要验证x=1的时候就行了,但是不知道怎么证明. 题解表示用数学归纳法,假设f(x)成立,证明f(x+1)成立需要什么条件. 代入之后发现有很多二项式系数,导致他们都是65的倍数,剩下的恰好就是 f(x) 和 18+ka . 那么只需要找到最小的a使得 18+ka是65的倍数. 题解说,毕竟65毕竟小,可以枚举a.因为a+65与a的对65的余数是一样的,所以只要枚举0到64就可以了. 我的

杭电 HDU 1097 A hard puzzle

A hard puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32851    Accepted Submission(s): 11754 Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius:  gave a