其他分享
首页 > 其他分享> > Codeforces Round #716 (Div. 2) 1514C

Codeforces Round #716 (Div. 2) 1514C

作者:互联网

C. Product 1 Modulo N

思路

AC

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef long long LL;
int gcd(int n, int t) {
	if (t == 0) return n;
	else return gcd(t, n % t);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	VI ans;
	LL res = 1;
	for (int i = 1; i <= n - 1; i ++ ) {
		if (gcd(n, i) == 1) {
			res *= i;
			res %= n;
			ans.PB(i);
		}
	}
	if (res != 1) {
		for (auto i = ans.begin(); i != ans.end(); i ++ ) {
			if (*i == res) {
				ans.erase(i);
				break;
			}
		}
	}
	cout << ans.size() << endl;
	for (auto t : ans) cout << t << ' ';
	return 0;
} 

标签:gcd,int,716,LL,long,1514C,Div,互质,mod
来源: https://blog.csdn.net/m0_53091571/article/details/118903514