Codeforces Round #334 (Div. 2) D(数论 循环节)
来源:互联网 发布:mac pscc2015安装教程 编辑:程序博客网 时间:2024/05/31 19:13
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 to p - 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,其中(0<=k<=p-1),x属于{0,1,2,3,....,p-1},f函数要满足f(k*x%p)=k*f(x)%p,f(x)的范围必须在[0.p-1]内,问这样的f函数有多少个
思路:
首先这个怎么看都跟循环节有关。。那么怎么找到循环节呢。。
首先找k为0的情况,可以发现此时答案就是p^(p-1)
然后k为1的情况,答案就是p^p
如果k>=2
很明显可以发现f(0)=0是肯定的
假设k^r%p=1,r是最小满足这个条件的正整数
那么f(x),因为f(x)在[0,p-1]内,
所以f(x)=k^r*f(x)%p=k^(r-1)*f(k*x%p)=k^(r-2)*f((k^2)*x%p)=k^(r-3)*f((k^3)*x%p)=....
=k^(r-r)*f((k^r)*x%p)=f((k^r)%p*x%p)=f(x%p)=f(x)
可以发现,在上面这个式子中,这r个x组成了一个环,这个环的数字只要确定一个x整个环就就知道了
本来x的范围中有p个数字,除去x=0的情况,还有p-1个数字。
又由费马小定理k^(p-1)%p=1,k^r%p=1,所以r肯定是p-1的因数
所以,p-1是肯定能整除r的,那么剩下的p-1个数字就能分成(p-1)/r个环
对于每个环上只要确定一个x就可以了,这个数字x有p种情况,即[0,p-1],一共有(p-1)/r个环
所以答案是p^((p-1)/r)
代码:
- Codeforces Round #334 (Div. 2) D(数论 循环节)
- Codeforces Round #334 (Div. 2) D(数论 循环节)
- 【数论】Codeforces Round #334 (Div. 2) D
- [数论] Codeforces Round #324 (Div. 2)D. Dima and Lisa
- Codeforces Round #338 div 2 D. Multipliers 数论
- Codeforces Round #338 (Div. 2)D-Multipliers(数论)
- Codeforces Round #382 (Div. 2) D. Taxes 数论、哥德巴赫猜想
- Codeforces Round #382 (Div. 2)D. Taxes(数论知识)
- Codeforces Round #382 (Div. 2) D Taxes(数论)
- Codeforces Round #226 (Div. 2) C 数论
- Codeforces Round #201 (Div. 2) C 数论
- Codeforces Round #325 (Div. 2) E 数论
- Codeforces Round #395 (Div. 2) E(数论)
- Codeforces Round #290 (Div. 2)D - Fox And Jumping——数论gcd=1
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数论 筛表法
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 数论 三素数定理
- Codeforces Round #386 (Div. 2) D. Green and Black Tea 数论+贪心
- Codeforces Round #422 (Div. 2) D. My pretty girl Noora(数论)
- javascript的学习
- JNI之c/c++返回中文给java 乱码问题以及java数组在c排序
- 服务端和客户端连接的两种方式,socket和DatagramSocket
- 存储管理之页式、段式、段页式存储
- 微服务架构的分布式事务解决方案
- Codeforces Round #334 (Div. 2) D(数论 循环节)
- modprobe和insmod的区别
- 在 2018 年来临之际,你应该知道的 Vue.js 的 11 个组件库
- FFMPEG中的内存读取
- VS中引用外部函数
- elasticSearch5.x单实例和集群安装
- codeforces 512C Fox And Dinner
- js或jquery实现页面打印
- 7个典型场景,学会互联网架构“解耦”