hdu1098:Ignatius's puzzle

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1098

参考链接:http://blog.csdn.net/baidu_23955875/article/details/42581983

费马小定理?!

看了参考链接中对费马小定理的解释后茅塞顿开

详细解释参见代码

代码:

 1 /**
 2  *费马小定理 :假如p是质数,且Gcd(a,p)=1,那么 a^(p-1) ≡1(mod p)。
 3  *即:假如a是整数,p是质数,且a,p互质(即两者只有一个公约数1),
 4  *那么a的(p-1)次方除以p的余数恒等于1。该定理是1636年皮埃尔·德·费马发现的。
 5  */
 6
 7 /**
 8  *f(x)=5x^13+13x^5+kax
 9  *设g(x)=f(x)/x/65 即g(x)=x^12/13+x^4/5+ka
10  *由费马小定理,g(x)实际上转化为g(x)=(13+5)/65+ka/65
11  *故枚举a即可
12  *而a>65之后实际上进入下一周期,故只需枚举到65
13  */
14
15 int main() {
16     int k;
17     while (~scanf("%d", &k)) {
18         int i;
19         for (i = 1; i <= 65; i++) {
20             if ((18 + k*i) % 65 == 0) {
21                 cout << i << endl;
22                 break;
23             }
24         }
25         if (i > 65) {
26             cout << "no" << endl;
27         }
28     }
29     return 0;
30 }

hdu1098:Ignatius's puzzle

时间: 2025-01-12 08:08:13

hdu1098:Ignatius's puzzle的相关文章

HDU1098 Ignatius&#39;s puzzle 【数论】

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

(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 费马小定理+扩展欧几里德算法

题目大意: 给定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中得到

杭电ACM1098——Ignatius&#39;s puzzle

这题,简单的数学题. 对于函数,f(x)=5*x^13+13*x^5+k*a*x,输入k,对于任意的x,是否存在一个数a,使得f(x)被65整除. 对于任意的x.所以当x = 1时,f(x) = 18 + a* k,满足被65整除. 也就是(18 + a * k)% 65 = 0. 所以,一切都很简单了. 下面的是AC的代码: #include <iostream> using namespace std; int main() { int k; while(cin >> k) {

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

Ignatius&#39;s puzzle

Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6948    Accepted Submission(s): 4797 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 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

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