题意:给出方程 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. bzoj 3676: [Apio2014]回文串 回文自动机

    3676: [Apio2014]回文串 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 844  Solved: 331[Submit][Status] ...

  2. PAT-乙级-1029. 旧键盘(20)

    1029. 旧键盘(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 旧键盘上坏了几个键,于是在敲一段文字的 ...

  3. The 7th Zhejiang Provincial Collegiate Programming Contest->Problem B:B - Somali Pirates

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3323 题意:去掉字符串里面的数字然后按输入顺序输出 #include< ...

  4. json中jobject

    Json.net codeplex :http://www.codeplex.com/Json 原本感觉Newtonsoft.Json和.net自己的JavaScriptSerializer相差无几, ...

  5. Servlet课程0425(七) 到数据库中去验证用户,同时防止SQL注入漏洞

    Login.java //登录界面 package com.tsinghua; import javax.servlet.http.*; import java.io.*; public class ...

  6. 网上图书商城项目学习笔记-035工具类之JdbcUtils及TxQueryRunner及C3P0配置

    事务就是保证多个操作在同一个connection,TxQueryRunner通过JdbcUtils获取连接,而JdbcUtils通过ThreadLocal<Connection>确保了不同 ...

  7. Java IO2:字节流

    输入输出流: • 输入/输出时, 数据在通信通道中流动. 所谓“数据流(stream)”指的是所有数据通信通道之中,数据的起点和终点. 信息的通道就是一个数据流.只要是数据从一个地方“流” 到另外一个 ...

  8. Maven中的一点疑惑的地方

    我们建立一个Maven项目,其结构如下:

  9. P151、面试题27:二叉搜索树与双向链表

    题目:输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向.(本质是中序遍历)二叉树结点的定义如下:struct BinaryTreeNod ...

  10. linux shell 常用基本语法

    转自网络,真正来源不详.... 一. Linux基本命令 1.1.  cp命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,功能十分强大. 语法: cp [选项] 源文件或目录 目标文件或 ...