【数学】CF1514 C

Problem - 1514C - Codeforces

题意:


【数学】CF1514 C_第1张图片

 

思路:

【数学】CF1514 C_第2张图片

Code:

#include 

using i64 = long long;

constexpr int N = 2e5 + 10;
constexpr int M = 2e5 + 10;
constexpr int mod = 998244353;

void solve() {
    int n;
    std::cin >> n;

    std::vector ans;
    i64 mul = 1ll;
    for (int i = 1; i <= n - 1; i ++) {
        if (std::__gcd(i, n) == 1) {
            ans.push_back(i);
            mul *= i;
            mul %= n;
        }
    }

    if (mul == 1ll) {
        std::cout << ans.size() << "\n";
        for (int i = 0; i < ans.size(); i ++) {
            std::cout << ans[i] << " \n" [i == ans.size() - 1];
        }
    }else {
        std::cout << ans.size() - 1 << "\n";
        for (int i = 0; i < ans.size() - 1; i ++) {
            if (ans[i] != n) {
                std::cout << ans[i] << " "; 
            }
        }
        std::cout << "\n";
    }
}
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    while(t --) {
        solve();
    }
    return 0;
}

 

你可能感兴趣的:(数学,算法)