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. Redis总体 概述,安装,方法调用

    1 什么是redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset( ...

  2. linux split 切割大文件

    语法: split  [-l <行数>] [-b <字节>] [-C <字节>] [要切割的目标文件] [输出文件名前缀] 说明: -l <行数> 指定 ...

  3. LocalDateTime与字符串互转/Date互转/LocalDate互转/指定日期/时间比较

    Java 8中表示日期和时间的类有多个,主要的有: Instant:表示时刻,不直接对应年月日信息,需要通过时区转换 LocalDateTime: 表示与时区无关的日期和时间信息,不直接对应时刻,需要 ...

  4. ZeroMQ API(四) 套接字

    1.创建一个套接字 1.1 zmq_socket(3) 1.1.1 名称 zmq_socket - 创建ZMQ套接字 1.1.2 概要 void * zmq_socket(void * context ...

  5. java类的定义

  6. Clockwise/Spiral Rule

    [Clockwise/Spiral Rule] There is a technique known as the ``Clockwise/Spiral Rule''. (顺时针螺旋法则). Ther ...

  7. Druid.io启用SQL支持

    Druid.io的SQL功能虽然在试验阶段,但是也支持了大部分的功能,而且还可以通过 Avatica JDBC查看请求的json,有助于我们理解Druid.io的语法.Druid.io有个比较坑的是, ...

  8. <eq>标签

    链接:http://document.thinkphp.cn/manual_3_2.html#taglib <eq name="menu.id" value="1& ...

  9. [转]激活函数ReLU、Leaky ReLU、PReLU和RReLU

    “激活函数”能分成两类——“饱和激活函数”和“非饱和激活函数”. sigmoid和tanh是“饱和激活函数”,而ReLU及其变体则是“非饱和激活函数”.使用“非饱和激活函数”的优势在于两点:    1 ...

  10. Qbot回归,已感染5.4万台计算机

    Qbot回归,已感染5.4万台计算机 近日,BAESystems的安全人员发表了一篇关于Qbot网络感知蠕虫回归的调查报告,指出已经感染了5.4万台计算机. FreeBuf百科 Qbot蠕虫,也叫Qa ...