Codeforces 487C Prefix Product Sequence(逆元)
来源:互联网 发布:太原易思软件 编辑:程序博客网 时间:2024/06/06 01:35
题目链接:Codeforces 487C Prefix Product Sequence
构造方式,从1开始,每次乘上i-1的逆元,再乘上i。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 5;ll ans[maxn] = {0, 1};int pow_mod(ll x, int n, int mod) {ll ret = 1;while (n) {if (n&1)ret = ret * x % mod;x = x * x % mod;n >>= 1;}return ret;}int inv (int a, int n) {return pow_mod(a, n-2, n);}int main () {int n;scanf("%d", &n);if (n == 1)printf("YES\n1\n");else if (n == 4)printf("YES\n1\n3\n2\n4\n");else {for (int i = 2; i < n; i++) {ans[i] = inv(i, n);if (n % i == 0) {printf("NO\n");return 0;}}printf("YES\n1\n");for (int i = 2; i < n; i++)printf("%lld\n", ans[i-1] * i % n);printf("%d\n", n);}return 0;}
0 0
- Codeforces 487C Prefix Product Sequence(逆元)
- Codeforces 487C. Prefix Product Sequence 逆元+构造
- codeforces 487 C Prefix Product Sequence 构造+逆元
- cf 487C Prefix Product Sequence 构造+逆元
- CodeForces 487C Prefix Product Sequence
- codeforces 487C Prefix Product Sequence
- codeforces 487C C. Prefix Product Sequence(数论+构造)
- codeforces 487C Prefix Product Sequence (模逆元+构造)
- CodeForces 487 C.Prefix Product Sequence(数论+构造)
- codeforces 488 E. Prefix Product Sequence
- Codeforces Round #278 (Div. 1) C. Prefix Product Sequence 模逆元,构造 2017/1/25
- Codeforces Round #278 (Div. 2) E. Prefix Product Sequence
- CodeForces 405C Unusual Product
- CodeForces 405C Unusual Product
- Codeforces 405C Unusual Product
- Codeforces 405C Unusual Product
- codeforces 405C Unusual Product
- CodeForces 13C Sequence
- ASP.NET MVC 导出CSV 的 CsvFileResult 类
- 各种排序算法汇总(交换排序:冒泡排序、快速排序)
- 找不到类型*它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 *serviceModel/serviceHostingEnvironment/serviceActiva
- HttpServletRequest中的getAttribute方法和getParameter方法的区别
- c++中endl到底是什么?
- Codeforces 487C Prefix Product Sequence(逆元)
- 【转载】struts2环境配置
- (Win7) PspCidTable遍历进程句柄表,枚举进程
- java5的CountDownLatch同步工具(十六)
- 【2015.2.9】重载、覆盖、隐藏、虚函数、纯虚函数
- 支持Explorer桌面的WinPE3.1纯净制作步骤与技术要点
- bzoj 1911 [Apio2010]特别行动队斜率优化+DP
- 【索引】Codeforces Round #278
- 偶遇Unslider