B - Moodular Arithmetic

题目大意:题意:告诉你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

否则

首先我们知道f(0) = 0;

我们到最小的 r 使得 k ^ r % p == 1。

那么f(x) ==  k ^ r * f(x)  == k ^ (r - 1) * f(k * x % p) == k ^ (r - 2) * f(k ^ 2 * x % p) ......... ==  f(k ^ r * x % p) == f(x % p) == f(x)

所以我们可以知道我们挑选了一个f(x)的值之后,我们就能确定 r 个函数的值。

所以我们只要挑(p - 1) / r 个值就能确定全部函数, 因为 k ^ (p - 1) % p == 1    k ^ r % p == 1

所以r一定能整除(p - 1)。 所以答案就是 p ^ ((p - 1) / r);

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> > using namespace std; const int N = 2e5 + ;
const int M = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; LL fastPow(LL a, LL b) {
LL ans = ;
while(b) {
if(b & ) ans = ans * a % mod;
a = a * a % mod; b >>= ;
}
return ans;
} LL p, k;
int main() { scanf("%lld%lld", &p, &k);
if(k == ) {
printf("%lld\n", fastPow(p, p - ));
} else if(k == ) {
printf("%lld\n", fastPow(p, p));
} else {
int m = ;
for(LL j = k; j != ; j = j * k % p) {
m++;
}
printf("%lld\n", fastPow(p, (p - ) / m));
}
return ;
}
/*
*/

Codeforces Round #334 (Div. 1) B. Moodular Arithmetic的更多相关文章

  1. Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数

    D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...

  2. 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 ...

  3. Codeforces Round #334 (Div. 2)

    水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...

  4. Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心

    C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...

  5. 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 ...

  6. Codeforces Round #481 (Div. 3) D. Almost Arithmetic Progression

    http://codeforces.com/contest/978/problem/D 题目大意: 给你一个长度为n的b(i)数组,你有如下操作: 对数组中的某个元素+1,+0,-1.并且这个元素只能 ...

  7. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

  8. 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)

    题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...

  9. Codeforces Round #334 (Div. 1) C. Lieges of Legendre

    Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...

随机推荐

  1. 转:zookeeper中Watcher和Notifications

    转自:http://www.tuicool.com/articles/B7FRzm 传统polling远程service服务 传统远程的service往往是这样服务的,服务提供者在远程service注 ...

  2. 通过网络仓库建立本地的yum仓库

    [root@kazihuo ~]# yum -y install createrepo yum-utils [root@kazihuo ~]# yum -y install https://mirro ...

  3. C#委托Code

    class Program { delegate double ProcessDelegate(double param1, double param2); static double Multipl ...

  4. MI-NOTE黑砖

    机型:MI NOTE LTE  miui7刷机老是报错,remote:partition table doesn't exist,分区表不存在,于是使用磁盘模式,也看到警告不要中途拔下来,但是不知道是 ...

  5. id=%d是什么意思呢?

    $branch=M('Branchs')->where("id=%d",session('branchid'))->find(); %d代表,逗号后面那个user[]的 ...

  6. 微服务深入浅出(5)-- 声明式调用Feign

    Feign的使用 Feign采用了声明式的API接口的风格,将Java Http客户端绑定到它的内部,从而调用过程变的简单. 配置文件: spring: application: name: eure ...

  7. CF448C Painting Fence

    传送门 Descriptionzed 最近总是受到 Farmer 的困扰,因此他在自家的门前插了一排栅栏以防农气的入侵.栅栏由 N 个竖条栅栏横向组成,每个竖条栅栏宽度为 1.过了一段时间,zed 觉 ...

  8. www.sojson.com网站高级JS加密破解

    在网上冲浪,看到了一个网站的JS加密,下面有一句话: 乍一看这句话吓一跳,我去这么猛,然后就很有兴趣想看看究竟是怎样一种加密算法. 对于破解JS加密算法的时候,都是先输入一个简单的语句然后分析加密后语 ...

  9. 20、List集合中特有的方法

    List里面的特有方法简介 List中除了Collection里面的方法以外,内部还有一些方法,通过这些方法,开发者可以更方便的操作List接口的实现类. package com.monkey1024 ...

  10. 《区块链100问》第85集:资产代币化之对标美元USDT

    USDT是Tether公司推出的对标美元(USD)的代币Tether USD.1USDT=1美元,用户可以随时使用USDT与USD进行1:1兑换.Tether公司执行1:1准备金保证制度,即每个USD ...