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堆,每堆 ...
随机推荐
- 《C++ Primer 4th》读书笔记 第9章-顺序容器
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936460.html
- Spring学习之AOP
Spring-AOP(Aspect-orented programming) 在业务流程中插入与业务无关的逻辑,这样的逻辑称为Cross-cutting concerns,将Crossing-cutt ...
- Android-给另一个Activity传递HashMap
I have a HashMap which I would pass to another Activity class. I simply use this code: Intent intent ...
- win10 enterprise 10240激活:
win10 enterprise 10240激活: 以管理员命令:slmgr /upkslmgr /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43slmgr /skms kms.x ...
- 动态创建WebService
WebService应用主要是为远程提供接口服务,远程通过代理方式获取WebService资源:但是在现实应用过程中,在Web或者应用程序中如果想用生成远程代理,一般是借助vs里提供的 添加-添加we ...
- Redis常用命令手册:服务器相关命令
Redis提供了丰富的命令(command)对数据库和各种数据类型进行操作,这些command可以在Linux终端使用.在编程时,比如各类语言包,这些命令都有对应的方法.下面将Redis提供的命令做一 ...
- 关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法
先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这 ...
- python 常用模块
1.os模块 os模块包装了不同操作系统的通用接口,使用户在不同操作系统下,可以使用相同的函数接口,返回相同结构的结果. os.name:返回当前操作系统名称('posix', 'nt', 'os2' ...
- 判断文件结束,feof……
因为文本文件中存储的是ASCII码,而ASCII码中FF代表空值(blank),一般不使用,所以如果读文件返回了FF,说明已经到了文本文件的结尾.但是如果是二进制文件,其中可能会包含FF,因此不能把读 ...
- 《Genesis-3D开源游戏引擎-官方录制系列视频教程:进阶实例篇》
注:本系列教程仅针对引擎编辑器:v1.2.2及以下版本 G3D进阶实例 第四课<2D编辑与脚本的统一入口> 使用G3D完成一个简单的类飞机大战游戏,介绍了G3D2d游戏制作的流程包括: ...