Codeforces 603B - Moodular Arithmetic 数论 应用群的基本性质
来源:互联网 发布:二年级体测数据 编辑:程序博客网 时间:2024/06/06 20:41
题意
- 一类函数,他们的定义域是{0,1,..,P-1},值域也是这个,但不一定是一一映射
- 其中p是奇数,且是质数
- 就是给你p和k,问你满足,给定的等式的函数有多少个,k是等式中的参数
- 等式是f(k * x % p) = k * f(x) % p。
- k的范围是0~p-1,p<10^6
思路
- 这题主要应用了群的性质,除去0的模p运算,是一个群
- 先不考虑0,让x和k都非0
- 我们先证明k * x % p的值各不相同,且会包含全部的1~p-1
- 假设k * x1 % p = k * x2 % p ,且x1 != x2
- 在群中,所以每个元素有逆元,那么k^-1 * k * x1 %p = k^-1 * k * x2 %p
- 所以x1 = x2,由此得证。
- 利用不停迭代,可以得出下面的关系:
- 任取x1,有f(x1) = k*f(x2)%p = k^2 * f(x3) % p = … = k^l * f(x1)
- x1 到 xl就凑成了一个循环的集合,确定x1,则其它元素的值都被确定了,所以对这样一个集合有f(x1)可以为0~p-1的任意值,所以有p种选择,所以找到所有这样的集合个数num,则ans = p ^ num
- 如何找到集合个数呢,我用的方法是用x1推xl,xl推xl-1,直到循环,xl = k * x1 % p
- 现在把0加回来,对于k可以特判k=0时,有p^p-1种,k=1时,有p^p种。
- 当k>1时,对于x=0时,我们固定让f(x) = 1,其它值有上述算法即可。
实现
#include <iostream>#include <cstring>#include <cmath>#include <cstdio>using namespace std;typedef long long ll;const ll mod = 1e9+7;const int maxn = 1000006;int vis[maxn];ll powll(ll x,ll y){ ll ret = 1; ll A = x; while (y > 0){ if (y&1) ret = ret * A % mod; A = A * A % mod; y >>= 1; } return ret;}int main(){ int p,k; cin>>p>>k; if (k == 0){ cout << powll(p,p-1) << "\n"; return 0; } if (k == 1){ cout << powll(p,p) <<'\n'; return 0; } int num = 0; for (int i=1;i<p;i++){ if (vis[i] == 1) continue; num++; int x = i; while (vis[x] != 1){ vis[x] = 1; x = (ll)k * (ll)x % p; } } cout << powll(p,num) <<'\n'; return 0;}
0 0
- Codeforces 603B - Moodular Arithmetic 数论 应用群的基本性质
- codeforces #334 div1 B 603B Moodular Arithmetic(数论)
- CodeForces 603 B. Moodular Arithmetic(数论+并查集)
- codeforces Moodular Arithmetic 数论
- 603B - Moodular Arithmetic
- Codeforces Round #334 (603B) Moodular Arithmetic [基础数学]
- 数论 Codeforces604D Moodular Arithmetic
- codeforces 604 D. Moodular Arithmetic
- 【codeforces 604D】Moodular Arithmetic
- 【Codeforces Round 334 (Div 2)D】【数论 置换群 典型数据特判 附带打表代码】Moodular Arithmetic 满足f(k x)=k f(x)的映射个数
- CF 334 div.2-D/div.1-B/603B Moodular Arithmetic
- Codeforces Round #334 D. Moodular Arithmetic(置换)
- Codeforces Round #334 D. Moodular Arithmetic(并查集)
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 思维
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic
- Codeforces Round #334 (Div. 2)-D Moodular Arithmetic(置换)
- CodeForces 628B(数论)
- C++显示类型转换
- GetMessage与PeekMessage的区别
- 学习Android开发的二十套免费理想资源
- Scala 内部类及外部类
- javaScript闭包
- Codeforces 603B - Moodular Arithmetic 数论 应用群的基本性质
- 链表常用操作算法集合
- 广工15新生赛 大数模拟运算
- 计算机网络_3_应用层
- python核心编程-partial函数
- BestCode_Round65_C题(线段树)
- 基础练习 闰年判断
- 树状数组求逆序对
- uva 489