HDUJ 1098 Ignatius's puzzle

Ignatius‘s puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6222    Accepted Submission(s): 4283

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
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		int m=0;
		for(int i=0;i<65;i++)
		{
			if((18+n*i)%65==0)
			{
				m=i;
				break;
			}
		}

		if(m)
			cout<<m<<endl;
		else
			cout<<"no\n";
	}

	return 0;
}

HDUJ 1098 Ignatius's puzzle

时间: 2024-11-03 00:52:31

HDUJ 1098 Ignatius's puzzle的相关文章

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

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

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 ACM 1098 Ignatius&#39;s puzzle

分析:裴蜀定理,a,b互质的充要条件是存在整数x,y使ax+by=1.存在整数x,y,使得ax+by=c,那么c就是a,b的公约数. 假设存在数a ,因为对任意x方程都成立,则有当x=1时f(x)=18+ka;有因为f(x)能被65整除,所以f(x)=n*65.即18+ka=n*65有整数解则说明假设成立. ax+by = c的方程有整数解的一个充要条件是:c%gcd(a, b) == 0.然后枚举直到(65*n-18)%k == 0. #include<iostream> using nam

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的困惑)

题目链接:http://vjudge.net/problem/HDU-1098 求解思路: f(x)=5*x^13+13*x^5+k*a*x; 其中题中"f(x)|65"表示对于任意的整数x,f(x)都能被65整除.所以不难推断:f(x+1)|65也成立. f(x+1)=5*(x+1)^13+13*(x+1)^5+k*a*(x+1), 根据二项式定理:(a+b)^n=C(n,0)a^n+C(n,1)a^(n-1)*b+C(n,2)a^(n-2)*b^2+...+C(n,n)b^n 得:

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*