HDU-1395 2^x mod n = 1】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1395 2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12146    Accepted Submission(s): 3797 Problem Description Give a number n, find…
题目大意: 求出一个最小的x 使得 2的x次方对n取模为1 思路分析: 若要 a*b%p=1  要使得b存在 则 gcd (a,p)=1. 那么我们应用到这个题目上来. 当n为偶数 2^x 也是偶数,那么gcd 肯定不是1.故这个是不存在的. 那么n为奇数的时候,也就一定是1了. 所以直接暴力找. #include <iostream> #include <cstdio> using namespace std; int main() { int n; while(scanf(&q…
题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == 0: 3)所以n肯定是除1外的奇数 代码如下: #include <iostream> using namespace std; int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n == 1 || n % 2 ==…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13341    Accepted Submission(s): 4143 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.  …
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15197    Accepted Submission(s): 4695 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.  …
策略 : 观察可知,1 或者是能被2整除的数都不会求余等于1, 仅仅须要推断一下是不是除1之外的奇数,在依次查找2^x(mod(n)) ? = 1就能够了 难点:假设每次都是在原来的基础上×2 再推断 会超时.这时候,要用一下同余定理就能够了 AC by SWS; 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1395 代码: #include<stdio.h> int main() { int n; while(scanf("%d&…
Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1. Input One positive integer on each line, the value of n. Output If the minimum x exists, print a line with 2^x mod n = 1. Print 2^? mod n = 1 otherwise. You sh…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16883    Accepted Submission(s): 5262 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.   I…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15810    Accepted Submission(s): 4914 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.   I…
联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvb29vb29vb29l/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""> 思路:与上题不同.这道题不要求m是素数.是利用扩展Baby Step Giant S…