题意:给出方程 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的更多相关文章

  1. CF# 334 Moodular Arithmetic

    B. Moodular Arithmetic time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

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

  3. 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( ...

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

  5. 【codeforces 604D】Moodular Arithmetic

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. cf Round 603

    A.Alternative Thinking(思维) 给出一个01串,你可以取反其中一个连续子串,问取反后的01子串的最长非连续010101串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...

  7. Codeforces Round #334 (Div. 2)

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

  8. Two progressions CodeForce 125D 思维题

    An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...

  9. [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...

随机推荐

  1. Mysql InnoDB彻底释放磁盘空间

    Innodb数据库对于已经删除的数据只是标记为删除,并不真正释放所占用的磁盘空间,这就导致InnoDB数据库文件不断增长. 如果需要彻底释放磁盘空间,则需要先导出数据,然后删除数据文件,最后导入数据. ...

  2. ExtJS4.2学习(二)Ext统一组件模型——Panel

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-06/171.html --------------- ...

  3. jquery 对 Json 的各种遍历

    grep <script type='text/javascript' src="/jquery.js"></script> <script type ...

  4. Windows2003/2008/2008 R2下易语言点支持库配置就退出的问题

    问题: 请问一个问题,我的电脑上win2003系统的,安装了易语言后,一点支持库配置就会自动退出.这是为什么啊? 解决方法如下: 删除 lib下的wmp.npk,重新打开易语言就可以了.

  5. c#带参数和返回值的函数 开启线程调用的方法

    public delegate string DgTest(); private void btn_District_Click(object sender, EventArgs e) { //实例化 ...

  6. iphone绘图的几个基本概念CGPoint、CGSize、CGRect、CGRectMake、window(窗口)、视图(view)

    我一般情况下不会使用interface builder去画界面,而是用纯代码去创建界面,不是装B,而是刚从vi转到xcode不久,不太习惯interface builder而已.当然如果需要我也会使用 ...

  7. Java 垃圾回收机制

    1.delete是C++里面用于释放内存的运算符,而不是Java. 2.当发现某个对象的引用计数为0时,就将对象列入待回收列表中,并不是马上予以销毁. 3.System.gc()仅仅是一个回收请求,J ...

  8. request重定向或者是response转发请求后面的代码依然执行

    调用response.redirect(),或者request.getRequestDispatcher(loginAddr).forward(request,response);后,后面的代码照样执 ...

  9. UIcollectionView的使用(首页的搭建2)

    2.2 直接购买的UIcollectionCell 2.2.1创建CFPromptBuyCell,继承自UICollectionViewCell,定义了标题和图片两个属性 2.2.2 在.m文件中定义 ...

  10. nginx几个知识点汇总

    WHY? 为什么用Nginx而不用LVS? 7点理由足以说明一切:1 .高并发连接: 官方测试能够支撑 5 万并发连接,在实际生产环境中跑到 2 - 3 万并发连接数.?2 .内存消耗少: 在 3 万 ...