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的一个常数。
思路:明显是求循环节的。
首先分析特殊情况:
k==0:f(x)=0.其余f(x)为值域中任何一个值,所以有p^(p-1)种;
k==1:f(x)=x.所以有p^(p)种;
其他:
若已知f(x)=n,则f(kx),f(k^2*x),f(k^3*x),...f(k^m*x)的值都求的出来;f(k^2*x%p)=k^2*f(x)%p=k*f(kx)%p;以此内推
当m到某个值时一定循环了,k^m=(同余)1%p;
转化成求m;
p^((p-1)/m);
- #include <bits/stdc++.h>
- #include<cmath>
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <cmath>
- typedef long long ll;
- using namespace std;
- const ll mod= 1e9+;
- ll pow1(ll x,ll n)
- {
- ll ret =;
- ll num =x;
- while(n)
- {
- if(n&)
- {
- ret*=num;
- ret%=mod;
- }
- num*=num;
- num%=mod;
- n>>=;
- }
- return ret;
- }
- int main()
- {
- int p,k;
- while(~scanf("%d%d",&p,&k))
- {
- if(k==)
- {
- printf("%64d\n",pow1(p,p-));
- continue;
- }
- if(k==)
- {
- printf("%64d\n",pow1(p,p));
- continue;
- }
- ll temp;
- temp=k;
- int m;
- for( m=;m<p;m++)
- {
- if(temp==)
- {
- break;
- }
- temp*=k;
- temp%=p;
- }
- int x=ceil((p-)*1.0/m);
- printf("%64d\n",pow1(p,x));
- }
- return ;
- }
codeforce 603B - Moodular Arithmetic的更多相关文章
- CF# 334 Moodular Arithmetic
B. Moodular Arithmetic time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- 【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串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...
- Codeforces Round #334 (Div. 2)
水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
随机推荐
- iOS 添加阴影后 屏幕卡顿 抖动
- (void)awakeFromNib { // Initialization code _btnViews.layer.shadowPath =[UIBezierPath bezierPathWi ...
- 【弱省胡策】Round #5 Construct 解题报告
这个题是传说中的 Hack 狂魔 qmqmqm 出的构造题.当然要神. 这个题的本质实际上就是构造一个图,然后使得任意两点间都有长度为 $k$ 的路径相连,然后对于任意的 $i < k$,都存在 ...
- Untiy 接入 移动MM 详解
原地址:http://www.cnblogs.com/alongu3d/p/3627936.html Untiy 接入 移动MM 详解 第一次接到师傅的任务(小龙),准备着手写untiy接入第三方SD ...
- Java 8 vs. Scala(一): Lambda表达式
[编者按]虽然 Java 深得大量开发者喜爱,但是对比其他现代编程语言,其语法确实略显冗长.但是通过 Java8,直接利用 lambda 表达式就能编写出既可读又简洁的代码.作者 Hussachai ...
- printf在终端输出时改变颜色
在调试程序时,有时候要输出大量数据,如果让printf/fprintf改变输出数据的颜色,那观察数据就方便多了. 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关.转义序 ...
- ***总结:在linux下连接redis并进行命令行操作(设置redis密码)
[root@iZ254lfyd6nZ ~]# cd / [root@iZ254lfyd6nZ /]# ls bin boot dev etc home lib lib64 lost+found med ...
- [java]2015上海邀请赛 B Base64
题意: 给n和一个字符串(可以有空格) 求字符串编码n次后的字符串 编码方式:字符串的每个字符转化成ASCII码, ASCII码转化成8位2进制, 将二进制数分割成6位为一组的(不够的补0), ...
- easyui源码翻译1.32--datagrid(数据表格)
前言 此前网上有easyui1.25的源码 应该算是比较老的版本 之后又经历了1.26 . 1.3. 1.31. 1.32 .1.33.1.34 1.33开始支持css3 算是又一个转折 但是 ...
- Linux防火墙iptables简明教程
前几天微魔部落再次遭受到个别别有用心的攻击者的攻击,顺便给自己充个电,复习了一下linux下常见的防火墙iptables的一些内容,但是无奈网上的很多教程都较为繁琐,本着简明化学习的目的,微魔为大家剔 ...
- 安装Hadoop系列 — 安装Eclipse
1.下载 Eclipse从 http://www.eclipse.org/downloads/index-developer.php下载合适版本,如:Eclipse IDE for C/C++ Dev ...