648.欧拉定理-最小x (10分)
C时间限制:1000 毫秒 | C内存限制:3000 Kb
题目内容:
给定一个n, 求满足 2^x =1 (mod n)的最小x.
输入描述
输入整数n
输出描述
输出最小的x, 或者输出“不存在”
输入样例
5
输出样例
4
思路: 由题意分析,2^x一定是偶数,所以当n为偶数或者为1时,不存在,其他的就存在,可以暴力了哈哈哈哈,
注意中途运算要取模,不然会炸。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int n;
cin >> n;
if(n % 2 == 0 || n == 1){
cout << "不存在" << endl;
}
else{
int x = 2;
int a = 2;
while(1){
a = a * 2 % n;
if(a % n == 1){
cout << x << endl;
break;
}
x++;
}
}
return 0;
}
浙公网安备 33010602011771号