Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数
D. Moodular Arithmetic
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/604/problem/D
Description
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that

for some function
. (This equation should hold for any integer x in the range 0 top - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 ≤ p ≤ 1 000 000, 0 ≤ k ≤ p - 1) on a single line. It is guaranteed that pis an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Sample Input
3 2
Sample Output
3
HINT
题意
给你k,p
然后让你构造映射 f(k*x %p) = k*f(x)%p
然后问你一共有多少种映射满足这个条件
题解:
由于gcd(k,p)==1,那么很显然k*x%p = z,这个等式中,x属于(0,p-1),z属于(0,p-1),那么的话,一定是一一对应的
那么我们就可以找环了,如果其中y = k*x%p中和其他的构成了一个环,那么这个环中只要确定了一个数,那么这个环中就能够全部确认
所以答案就和环的个数有关了~
再特判k = 1和k = 0的情况
代码:
#include<iostream>
#include<stdio.h>
using namespace std; const long long mod = 1e9+; #define maxn 1000005
long long quickpow(long long m,long long n)
{
long long b = ;
while (n > )
{
if (n & )
b = (b*m)%mod;
n = n >> ;
m = (m*m)%mod;
}
return b;
} long long a[maxn];
int vis[maxn];
long long p,k;
void dfs(long long x)
{
if(vis[x])return;
vis[x]=;
dfs(k*x%p);
}
int main()
{ scanf("%lld%lld",&p,&k);
if(k==)
{
printf("%lld\n",quickpow(p,p-));
return ;
}
if(k==)
{
printf("%lld\n",quickpow(p,p));
return ;
}
long long ans = ;
for(int i=;i<p;i++)
{
if(vis[i])continue;
dfs(i);
ans++;
}
printf("%lld\n",quickpow(p,ans));
}
Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数的更多相关文章
- Codeforces Round #334 (Div. 1) B. Moodular Arithmetic
B - Moodular Arithmetic 题目大意:题意:告诉你p和k,其中(0<=k<=p-1),x属于{0,1,2,3,....,p-1},f函数要满足f(k*x%p)=k*f( ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #334 (Div. 2)
水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...
- Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...
- Codeforces Round #334 (Div. 2) B. More Cowbell 二分
B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/probl ...
- Codeforces Round #481 (Div. 3) D. Almost Arithmetic Progression
http://codeforces.com/contest/978/problem/D 题目大意: 给你一个长度为n的b(i)数组,你有如下操作: 对数组中的某个元素+1,+0,-1.并且这个元素只能 ...
- 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)
题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
- 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)
题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...
- Codeforces Round #334 (Div. 1) C. Lieges of Legendre
Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...
随机推荐
- SQL优化34条
我们要做到不但会写SQL,还要做到写出性能优良的SQL,以下为笔者学习.摘录.并汇总部分资料与大家分享! (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析 ...
- 安装oracle XML Database 组件
近期部署项目数据库,编译包时遇到错误: PACKAGE CTG.CTG_CSB_COMMON 编译错误 错误:PLS-00201: identifier 'XMLDOM' must be dec ...
- 怎样查看Eclipse是32位还是64位
首先进入到Eclipse的安装目录,如下图: 查找到文件名为"eclipse.ini" 文件,使用文本编辑工具,或记事本打开,如下图: 如图中的红框所示,如果是win32.x8 ...
- 同行评审 Peer Review
周五的课上,章老师给我们上了一节关于同行评审(Peer Review)的课程,让我了解了以前并不熟悉的这一过程.课上我们就姚思丹同学项目组做的项目,分组进行了审查. 首先介绍一下同行评审(Peer R ...
- Linux基本命令(2)有关磁盘空间的命令
有关磁盘空间的命令 命令 功能 mount 挂载文件系统 umount 卸载已挂载上的文件系统 df 检查各个硬盘分区和已挂上来的文件系统的磁盘空间 du 显示文件目录和大小 fsck 主要是检查和修 ...
- 【和我一起学python吧】python的数据类型
python的元组.列表.字典数据类型是很python(there python is a adjective )的数据结构.这些结构都是经过足够优化后的,所以如果使用好的话,在某些area会有很大的 ...
- CORBA
公共对象请求代理体系结构(Common Object Request Broker Architecture)
- dedecms
http://www.duodede.com/free/ [free templte] http://www.xiuzhanwang.net/d
- unix文件权限
一.UNIX下关于文件权限的表示方法和解析 SUID 是 Set User ID, SGID 是 Set Group ID的意思. UNIX下可以用ls -l 命令来看到文件的权限.用ls命令所得到的 ...
- Com进程通信(Delphi2007)
相关资料: 1.http://my.oschina.net/u/582827/blog/2847662.http://www.cnblogs.com/findumars/p/5277561.html3 ...