题意:给出方程 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. MCM试题原文及翻译 AB题 2014美国数学建模竞赛

    MCM试题原文及翻译 AB题 2014美国数学建模竞赛 原创翻译,如有瑕疵,敬请谅解. 转载请注明:过客小站 » MCM试题原文及翻译 AB题 2014美国数学建模竞赛 PROBLEM A: The  ...

  2. Eclipse 插件开发 —— 深入理解查找(Search)功能及其扩展点

    引言 查找功能是计算机语言开发环境 / 平台的一个非常重要的特性.Eclipse 也不例外,它提供了丰富的查找功能(用户可以输入正则表达式或任意字符串,指定查找范围和匹配选项等等),并且提供了简单易用 ...

  3. C: 数组形参

    知识这个东西,真是知道的越多就不知道的越多,C/C++这塘水得多深啊,哈哈.看下面3个片段:<一> 1 void fun(char a[100]) { 2         fprintf( ...

  4. DJANGO和UIKIT结合,作一个有进度条的无刷新上传功能

    以前作的上传,在糙了,所以在用户体验上改进一下. 同时,结合DJANGO作定位上传. 这其中分两步进行,第一次上传到TMP目录下, 第二次,将TMP下的文件转移到标准目录下. form.py file ...

  5. Android ListView相关 fastScrollEnabled

    1.android:fastScrollEnabled="true" 当数据量比较多的时候,右侧会出现一个可以拉动的滚动条,这样可以很快的拉动,如图:

  6. 如何用DELPHI编程修改外部EXE文件的版本信

    右击里面有修改 点开直接修改就可以了吧. DELPHI 里程序的版本信息怎么是灰色的,无法更改 耐心读以下说明,应该能解决你的问题,如果不能解决,请Hi我~ 如何给自己的dll文件添加版本信息呢? 首 ...

  7. 生成整数自增ID(集群主键生成服务)

        在集群的环境中,有这种场景     需要整数自增ID,这个整数要求一直自增,并且需要保证唯一性. Web服务器集群调用这个整数生成服务,然后根据各种规则,插入指定的数据库.        一般 ...

  8. (从终端看linux-2)浅析terminal创建时ptmx和pts关系

    我们打开一个terminal,那么将会在devpts文件系统/dev/pts下创建一个对应的pts字符文件,该pts字符文件节点直接由/dev/ptmx节点的驱动函数ptmx_open()调用devp ...

  9. php curl下载图片 URL地址

    <?php $url = 'http://mf1905.com/upload/video_img/df3074c98ec5124ad47c52ff59f74e04_middle.jpeg'; f ...

  10. Linux内核3.0移植并基于Initramfs根文件系统启动

    Linux内核移植与启动 Target borad:FL2440 Bootloader:U-boot-2010.09 交叉编译器:buildroot-2012.08 1.linux内核基础知识 首先, ...