HDOJ1395 2^x mod n = 1
2017-12-08 17:05
197 查看
2^x mod n = 1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18046 Accepted Submission(s): 5656
[align=left]Problem Description[/align]
Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.
[align=left]Input[/align]
One positive integer on each line, the value of n.
[align=left]Output[/align]
If the minimum x exists, print a line with 2^x mod n = 1.
Print 2^? mod n = 1 otherwise.
You should replace x and n with specific numbers.
[align=left]Sample Input[/align]
2
5
[align=left]Sample Output[/align]
2^? mod 2 = 1
2^4 mod 5 = 1
可以使用暴力法直接解决。不过在每次乘的时候都求一次余。
import java.util.Scanner; //2^x mod n = 1. public class Main{ private static Scanner scanner; public static void main(String[] args) { scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); int x = 1; boolean isMod = false; for (int i = 1; i <= n; i++) { x = x * 2 % n; if (x == 1) { System.out.println("2^" + i + " mod " + n + " = 1"); isMod = true; break; } } if (!isMod) { System.out.println("2^? mod " + n + " = 1"); } } } }
相关文章推荐
- HDOJ 题目1395 2^x mod n = 1(水题 易错)
- hdoj1395 (数学水题)2^x mod n = 1
- 2^x mod n = 1 hdoj 1395
- HDOJ-1395-2^x mod n = 1 解题报告
- HDOJ 1395 2^x mod n = 1
- HDOJ 1395 2^x mod n = 1
- [HDOJ1395]2^x mod n = 1(欧拉函数)
- hdoj 1395 2^x mod n = 1
- hdoj 1395 2^x mod n = 1 【暴力】
- 【HDOJ】1395 -> 2^x mod n = 1
- HDOJ 1395 2^x mod n = 1
- HDU/HDOJ 1395 ACM浙大月赛 2^x mod n = 1
- hdoj1395 2^x mod n = 1
- HDU/HDOJ 1395 ACM浙大月赛 2^x mod n = 1 可暴力 可用欧拉定理
- hdoj 1395 2^x mod n = 1 【暴力】
- hdoj-1395-2^x mod n = 1【欧拉定理】
- 2^x mod n = 1 【杭电-HDOJ-1395】 附题
- ACM 数论 hdu 1395 2^x mod n = 1
- hdu 1395 2^x mod n = 1
- (step7.2.1)hdu 1395(2^x mod n = 1——简单数论)