题目链接: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&…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1395 这题一定要滴水不漏的把所有代码全部看完. 这个题目是一个数学类型的题,我也没思路,只知道n==1||n%2==0时,x是找不到的,其他则不知道还有没有n存在x是找不到的, 还有一个,暴力搜索时不知道搜到哪里为止,提交,则超时,看了别人的博客:如果a和n互质且a<n则a^x%n=1,因此在此题中,a为2 所以只要a!=1&&a%2!=0,则一定存在x, #include<st…
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…