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 ...
随机推荐
- 如何将word中上下两行文字对齐?
一.问题来源及描述 本科毕设的时候积累的问题,整理如下. 红头文件下面的署名,上下要对齐. 二.解决办法 经验证,第一次拉标尺要把标尺放在第一行的光标处,为了换行后,再次enter,tab后到与上一行 ...
- python time相关操作
1.获取当前时间的两种方法: 代码如下: import datetime,timenow = time.strftime("%Y-%m-%d %H:%M:%S")print now ...
- POJ3258River Hopscotch(二分)
http://poj.org/problem?id=3258 题意:有一条很长很直的河距离为L,里边有n块石头,不包括起点和终点的那两块石头,奶牛们会从一个石头跳到另外一个,但因为有的石头隔得太近了, ...
- MyBatis-Spring 执行SQL语句的流程
1. 从SqlSessionDaoSupport开始 通常我们使用MyBatis会让自己的DAO继承SqlSessionDaoSupport,那么SqlSessionDaoSupport是如何运作的呢 ...
- AAC ADTS AAC LATM 格式分析
http://blog.csdn.net/tx3344/article/details/7414543# 目录(?)[-] ADTS是个啥 ADTS内容及结构 将AAC打包成ADTS格式 1.ADTS ...
- memcached部署memcached环境及PHP扩展
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lxsym.blog.51cto.com/1364623/876209 Memca ...
- 解决 Your project contains error(s),please fix them before running your application问题
原文地址: Android笔记:解决 Your project contains error(s),please fix them before running your application问题 ...
- paip.提升用户体验----gcc c++ JIT-debugging 技术
paip.提升用户体验----gcc c++ JIT-debugging 技术 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http ...
- [置顶] Maven多模块项目 eclipse热部署 Maven项目实现 tomcat热部署 二
最近看到有好多童鞋比较热衷热部署,特别是多模块的项目,其实这热部署如果多模块比较大资源,容易内存溢出或者电脑卡住,并不建议这么做. 不过了解下也没有关系,这里我就在说说热部署的另外一种方法,因为我之前 ...
- Foreman--Puppet类导入
一.Foreman环境: foreman建好后,系统默认创建了3个环境:production,development,common, 1. production: 在puppet.conf里已经定义其 ...