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串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...
随机推荐
- python基础——使用__slots__
python基础——使用__slots__ 正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: cla ...
- UVA 111 History Grading
读题读了好久,其实就是在输入数据时要对数据的位置进行相应的改变 #include<iostream> #include<cstring> #include<cstdio& ...
- 在Win7 64位注册ActiveX控件
首先必须以管理员身份运行cmd.exe,即在cmd.exe右键选择以管理员身份运行. 目前共有两个存在网络盘的文件需要注册,一个dll,一个ocx. 开始时将两个文件都拷贝到c:\wind ...
- 【JAVA多线程概述】
一.多线程概述 一个进程中至少有一个线程,每一个线程都有自己运行的内容,这个内容可以称为线程要执行的任务. 不能没一个问题都使用多线程,能使用单线程解决的问题就不要使用多线程解决. 使用多线程的弊端: ...
- 查看MYSQL中数据表占用的空间
由于数据太大了.所以MYSQL需要瘦身,那前提就是需要知道每个表占用的空间大小. 首先打开指定的数据库: use information_schema; 如果想看指定数据库中的数据表,可以用如下语句: ...
- 无废话ExtJs 入门教程十六[页面布局:Layout]
无废话ExtJs 入门教程十六[页面布局:Layout] extjs技术交流,欢迎加群(201926085) 首先解释什么是布局: 来自百度词典的官方解释:◎ 布局 bùjú: [distributi ...
- makefile基础(GNU)
makefile的核心 targets : prerequisites ; commands... //不分行的情况 targets : prerequisites ...
- 构造方法 static 块 {}块 执行顺序
package com.test.innerclass; public class HelloB extends HelloA { public HelloB() { System.out.print ...
- 2016"百度之星" - 初赛(Astar Round2A)All X(数学 矩阵)
All X Accepts: 1281 Submissions: 7580 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- Linux下修改默认字符集--->解决Linux下Java程序种中文文件夹file.isDirectory()判断失败的问题
一.问题描述: 一个项目中为了生成树状目录,调用了file.listFiles()方法,然后利用file.isDirectory()方法判断是否为目录,该程序在windows下运行无问题,在Linux ...