BZOJ3884【数论】
来源:互联网 发布:电脑桌面有什么软件 编辑:程序博客网 时间:2024/06/06 00:11
/* I will wait for you*/#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <algorithm>#include <iostream>#include <fstream>#include <vector>#include <queue>#include <deque>#include <map>#include <set>#include <string>#define make make_pair#define fi first#define se secondusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int,int> pii;const int maxn = 10000010;const int maxm = 1010;const int maxs = 26;const int inf = 0x3f3f3f3f;const int P = 1000000007;const double error = 1e-9;inline int read(){int x = 0, f = 1;char ch = getchar();while (ch <= 47 || ch >= 58)f = (ch == 45 ? -1 : 1), ch = getchar();while (ch >= 48 && ch <= 57)x = x * 10 + ch - 48, ch = getchar();return x * f;}int pri[maxn], in[maxn], fai[maxn];void init(){memset(pri, inf, sizeof pri);fai[1] = pri[1] = 1;for (int i = 2; i * i < maxn; i++)if (!in[i]) {pri[i] = i;for (int j = i * i; j < maxn; j += i) in[j] = 1, pri[j] = min(pri[j], i);}for (int i = 2; i < maxn; i++) {if (!in[i])fai[i] = i - 1;else {if (pri[i] == pri[i / pri[i]])fai[i] = fai[i / pri[i]] * pri[i];elsefai[i] = fai[i / pri[i]] * (pri[i] - 1);}}}int t;int qpow(int n, int p){ll ans = 1;for (ll a = 2; n; (a *= a) %= p, n /= 2)(n & 1) ? (ans *= a) %= p : 0;return ans;}int solve(int n){if (n == 1)return 0;int k = 0, p = n;for (; p % 2 == 0; k++, p /= 2);ll tmp = solve(fai[p]) - k;while (tmp < 0)tmp += fai[p];tmp = n / p * qpow(tmp, p) % n;return (int) tmp;}int main(){t = read(), init();while (t--) {int n = read(), m = solve(n);printf("%d\n", m);}return 0;}
0 0
- BZOJ3884【数论】
- 数论专题练习:【bzoj3884】上帝与集合的正确用法
- 【bzoj3884】【上帝与集合的正确用法】【数论】
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论 ?
- 数论
- 数论
- 数论
- Dialogue System for Unity文档中英对照版(简雨原创翻译)完结篇(内置脚本使用,脚本API)
- oracle插入sql
- MAC打开EXE文件的三大方法
- css定位问题
- 数据结构—单链表的排序以及逆置
- BZOJ3884【数论】
- Spring学习笔记(14)-----------aop学习转折点(1)
- 我的 ”三个一切“
- C# 并行编程 之 并发集合 (.Net Framework 4.0)
- C C语言概述
- Android_照相机Camera_调用系统照相机返回data为空
- 6LowPAN——最后一公里接入
- 模拟新浪微博随便看看界面布局
- Spring学习笔记(15)-----------Spring转折点(2)