CF# 334 Moodular Arithmetic
1 second
256 megabytes
standard input
standard output
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.
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 p is an odd prime number.
Print a single integer, the number of distinct functions f modulo 109 + 7.
3 2
3
5 4
25
In the first sample, p = 3 and k = 2. The following functions work:
- f(0) = 0, f(1) = 1, f(2) = 2.
- f(0) = 0, f(1) = 2, f(2) = 1.
- f(0) = f(1) = f(2) = 0.
题意:给出p,k,问满足f(kx % p) = k*f(x) % p,其中0 <= f(i) < p的映射有多少种。
分析:显然f(0) = 0
考虑其他的,
如果我们确定了一个f(i),我们会通过f(i)确定很多的映射,比如f(ki % p), f(k^2 i % p).....
什么时候会停下来?
当k^t = 1 (mod p)时会停下来。
那么就是说我们每确定一个数,就有t个数确定了。
这里的t可以通过枚举算出。
就是说我们一共只能确定(p-1)/t个数,每个数有p种可能。
ans=p^((p-1)/t)
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} int p, k;
vector<int> factor; inline void Input()
{
scanf("%d%d", &p, &k);
} inline int Power(int b, int t, int mod = )
{
int ret = ;
while(t)
{
if(t & ) ret = (1LL * ret * b) % mod;
b = (1LL * b * b) % mod, t >>= ;
}
return ret;
} inline void Ext_Gcd(int a, int b, int &x, int &y)
{
if(b == ) x = , y = ;
else
{
Ext_Gcd(b, a % b, x, y);
int t = x;
x = y;
y = t - (a / b) * x;
}
} inline void Solve()
{
if(k == )
{
printf("%d\n", Power(p, p - ));
return;
} if(k == )
{
printf("%d\n", Power(p, p));
return;
} /*int x, y;
Ext_Gcd(k, p, x, y);
if(y <= 0)
{
int t = y / k + 1;
x -= t * p, y += t * k;
} int s;
LL t;
for(s = 1, t = k; ((t - x) % p + p) % p != 0; t *= k, s++) ;*/ int t = p - ;
for(int i = ; i * i <= t; i++)
if(t % i == )
{
factor.pub(i);
factor.pub(t / i);
}
sort(factor.begin(), factor.end()); int len = factor.size(), s;
for(int i = ; i < len; i++)
if(Power(k, factor[i], p) == )
{
s = factor[i];
break;
} int ans = Power(p, (p - ) / s);
printf("%d\n", ans);
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
CF# 334 Moodular Arithmetic的更多相关文章
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数
D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...
- 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( ...
- CF 334 div.2-D Moodular Arithmetic
思路: 易知k = 0的时候答案是pp-1,k = 1的时候答案是pp. 当k >= 2的时候,f(0) = 0,对于 1 <= n <= p - 1,如果f(n)确定,由题意可知f ...
- CF 1114 E. Arithmetic Progression
E. Arithmetic Progression 链接 题意: 交互题. 有一个等差序列,现已打乱顺序,最多询问60次来确定首项和公差.每次可以询问是否有严格大于x的数,和查看一个位置的数. 分析: ...
- CF# 334 Lieges of Legendre
C. Lieges of Legendre time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CF# 334 Alternative Thinking
A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforce 603B - Moodular Arithmetic
题意:给出方程 f(kx%p)=kf(x)%p ,f:A->B,不同的映射函数f有几种,其中f,A,B值域为{0,1,2..p-1},p为素数(除了2),k为小于p的一个常数. 思路:明显是求循 ...
- 【codeforces 604D】Moodular Arithmetic
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- cf Round 603
A.Alternative Thinking(思维) 给出一个01串,你可以取反其中一个连续子串,问取反后的01子串的最长非连续010101串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...
随机推荐
- 经典.net试题
经典.net面试题目 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. pr ...
- C语言扩展Python模块
1. 先创建一个PythonDemo.cpp文件: //c/c++中调用python脚本,配置步骤参见上一篇:C/C++与python交互 \ C/C++中调用python文件. #include ...
- Qt中如何添加.qrc文件
You need a resource file (.qrc) within which you embed the input text file. The input file can be an ...
- 端口扫描之王-----------nmap
[root@ok data]# nmap -F -sT -v nmap.org Starting Nmap 5.51 ( http://nmap.org ) at 2016-10-23 12:46 C ...
- CLR via C#(06)- 构造器
最近忙着看新还珠,好几天不学习了.玩物丧志啊,罪过罪过. 今天总结的是类构造器的知识,其实这方面的文章蛮多的,可还是觉得亲自写一下对自己的思考和认识会有提高. 对于构造器,大家应该都不陌生,它主要是用 ...
- 排序练习【sdut 1582】【堆排序】
排序 Time Limit: 1000ms Memory limit: 32678K 有疑问?点这里^_^ 题目描述 给你N(N<=100)个数,请你按照从小到大的顺序输出. 输入 输入数 ...
- AOJ673 聪明的输入法(字典树)
#include<cstdio> #include <cstdlib> #include <cstring> #include <iostream> # ...
- .Net Ioc Unity
Unity 的接口IUnityContainer public interface IUnityContainer : IDisposable IUnityContainer RegisterType ...
- PHP json数据格式化方法
php 的json_encode能把数组转换为json格式的字符串.字符串没有缩进,中文会转为unicode编码,例如\u975a\u4ed4.人阅读比较困难.现在这个方法在json_encode的基 ...
- JS常用语句
JavaScript常用语句 1.document.write(""); 输出语句 2.JS中的注释为 // 3.传统的HTML文档顺序是: document-& ...