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堆,每堆 ...
 
随机推荐
- Oracle中将小数转换成字符丢零.截取小数.除数为零解决法
			
如下所示,前面少个0 SQL>select money from users where username ='LEI'; money --------- .3256 解决方法: SQL> ...
 - jsoup使用选择器语法来查找元素
			
问题 你想使用类似于CSS或jQuery的语法来查找和操作元素. 方法 可以使用Element.select(String selector) 和 Elements.select(String sel ...
 - wait函数返回值总结
			
之前在学习wait和waitpid函数的时候,就对使用宏WIFEXITED来检查获取的进程终止状态产生过疑惑:一般我们在程序中是调用的exit或者_exit函数来退出的,那么wait和waitpid函 ...
 - java web 学习六(servlet开发2)
			
一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...
 - aspx与ascx,ashx的用法详细的总结介绍
			
这篇文章主要是对aspx与ascx,ashx的用法进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助 做asp.net开发的对.aspx,.ascx和.ashx都不会陌生.关于它们,网 ...
 - Ubuntu 12.04中文输入法的安装
			
Ubuntu 12.04中文输入法的安装 Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu ...
 - 【转】Yahoo!团队:网站性能优化的35条黄金守则
			
Yahoo!的 Exceptional Performance团队为改善 Web性能带来最佳实践.他们为此进行了一系列的实验.开发了各种工具.写了大量的文章和博客并在各种会议上参与探讨.最佳实践的核心 ...
 - 第四章:更多的bash shell命令
			
第四章:更多的bash shell命令 监测程序 ps (其他ps内容见#1 ) Unix风格的ps命令参数 参数 描述 -A 显示所有进程 -N 显示与指定参数不符的所有进程 -a 显示除控制进程( ...
 - restsharp发送服务端请求回传session
			
今天工作遇到这样一个场景,我需要获取一个游戏目录列表,这个列表接口在线上已经存在,但是这个接口需要登录认证后才能获取到,所以实现这个功能我打算分两部来做: 1.首先调登录接口,以写上session 2 ...
 - 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇08:弹幕系统》本系列完结
			
8.弹幕系统 弹幕系统概述: 弹幕系统的设计体现了射击游戏的基本要素,玩家要在敌人放出的大量子弹(弹幕)的细小空隙间闪避,能在玩家闪躲弹幕的时候给玩家带来快感,接近满屏的子弹,增加了对玩家的视觉冲击力 ...