C. Product 1 Modulo N

1 <= C <= n - 1
B % n = C
—> A * C % n = C
—> A % n * C % n = C
—> 1 * C = C
—> A % n = 1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 9;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
int t = 1, n, m, k;
vector <int> ans;
int main()
{
/*cin >> t;
while(t--)
{
}*/
scanf("%lld", &n);
ll sum = 1;
for(int i = 1; i < n; ++i)
{
if(__gcd(n, i) == 1){
ans.push_back(i);
sum = (sum * i) % n;
}
}
if(sum == 1)
{
printf("%d\n", ans.size());
for(auto &x : ans) printf("%d ",x);cout << '\n';
}
else
{
printf("%d\n", ans.size() - 1);
for(auto &x : ans)
if(x != sum) printf("%d ", x); cout << '\n';
}
return 0;
}

该博客探讨了模运算在数学和编程中的应用,通过C.Product1ModuloN问题展示模运算的性质。文章指出,当1≤C≤n-1且B%n=C时,可以推导出一系列关于模的等式,最终得出A%n=1的结论。程序部分展示了如何找到所有与n互质的数,并根据模运算性质解决特定问题。
364

被折叠的 条评论
为什么被折叠?



