51Nod 1135:元根(数论)】的更多相关文章

[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60802734 1 离散对数 离散对数定义 大步小步走 2 元根 一些概念 阶和元根 例题 1离散对数 定义 给定a,b,m,其中a与m互素,求最小的非负(正)整数x,使得: a^x≡b (mod m) 我们称x为模m意义下,以a为底的b的离散对数,记作ind a b. 那么,给出a,b,m,(假设a与m互素)如何求x? 大步小步走 这有一个技巧:显然,任…
题目链接:51nod 1135 原根 设 m 是正整数,a是整数,若a模m的阶等于φ(m),则称 a 为 模m的一个原根.(其中φ(m)表示m的欧拉函数) 阶:gcd(a,m)=1,使得成立的最小的 r,称为 a 对 模m 的 阶. φ(m):在[1,m)的区间内与m互质的数的个数. 求模素数p的原根a的方法: 因为p为素数,所以φ(p)=p-1, 这题就是要找最小的a使得 a^(p-1)%p = 1 成立(根据费马小定理,该式一定成立), 先求p-1所有不同的 质因子 p1,p2-pm, 对任…
1135 原根  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根.(其中φ(m)表示m的欧拉函数) 给出1个质数P,找出P最小的原根. Input 输入1个质数P(3 <= P <= 10^9) Output 输出P最小的原根. Input示例 3 Output示例 2 AC代码 就是找到最小的数x,使 #include <stdio.h> #include &l…
题目链接 建议与上一篇欧拉函数介绍结合食用. 知识点:1.阶:a和模m互质,使a^d≡1(mod m)成立的最小正整数d称为a对模m的阶(指数)   例如: 2^2≡1(mod3),2对模3的阶为2; 2^3≡1(mod7),2对模7的阶为3;2.欧拉函数φ(m):在[1,m)的区间内与m互质的数的个数.可见前一篇blog3.设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根. 求模素数p的原根a的方法: 对质数 p, φ(p) = p-1, 这题就是要找最小的a使得 a^…
设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根.(其中φ(m)表示m的欧拉函数)   给出1个质数P,找出P最小的原根. Input 输入1个质数P(3 <= P <= 10^9) Output 输出P最小的原根. Input示例 3 Output示例 2解:使用快速幂的时候小心int爆了. #include <stdio.h> #include <math.h> #include <string.h> #define CLR(x)…
1225 余数之和 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 Description F(n) = (n % 1) + (n % 2) + (n % 3) + ...... (n % n).其中%表示Mod,也就是余数. 例如F(6) = 6 % 1 + 6 % 2 + 6 % 3 + 6 % 4 + 6 % 5 + 6 % 6 = 0 + 0 + 0 + 2 + 1 + 0 = 3. 给出n…
https://www.51nod.com/Challenge/Problem.html#!#problemId=1363 求\(\sum\limits_{i=1}^{n}lcm(i,n)\) 先换成gcd: \(\sum\limits_{i=1}^{n}\frac{i*n}{gcd(i,n)}\) 显而易见,枚举g: $ n * \sum\limits_{g|n} \frac{1}{g} \sum\limits_{i=1}^{n} i*[gcd(i,n)==g] $ 提g,没有下整符号: $…
%%% dalao Orz ,筛素数到sqrt(n),分解ϕ(p),依次枚举判断就好了 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #define N 100000 #define LL long long using namespace std; LL prime[100010],tot,cnt,p[10001…
题意 题目链接 Sol 可以证明素数的原根不会超过他的\(\frac{1}{4}\) 那么预处理出\(P - 1\)的所有的质因数\(p_1, p_2 \dots p_k\),暴力判断一下,如果$\exists i, a^{\frac{P - 1}{p_i}} \equiv 1 \pmod {P - 1} $ 那么说明\(a\)不是\(P\)的原根,因为根据原根的定义,需要保证\(P-1\)是第一个满足\(a^{P - 1} \equiv 1 \pmod {P - 1}\)的数 #include…
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; ; ; LL a[MAXN], sum[MAXN], ans[MAXN]; int main() { int n, m; while(cin>>n>>m) { ; i<=n; i++) scanf("%lld",&…