题意:给出方程 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. Discuz云平台站点信息同步失败,An unknown error occurred. May be DNS Error.

    站点信息同步失败 An unknown error occurred. May be DNS Error. (ERRCODE:1) 经过Discuz教程网(http://www.1314study.c ...

  2. 1989-C. 数字三角形

    描述 如图所示,是一个数字搭成的三角形. 若起始位置在三角形的顶端,结束位置在三角形底边,每一步只能向下方或向右下角移动一格.请编程计算一条路径,使得路径上经过的数字和最大.(图中路径7→3→8→7→ ...

  3. HDU 1429 胜利大逃亡(续)(三维BFS)

    题目链接 题意 : 中文题不详述. 思路 : 这个题和1885差不多一样的,所以我直接改了改那个代码就交上了,链接 #include <stdio.h> #include <stri ...

  4. poj 3440 Coin Toss 概率问题

    这题主要是推导数学公式!!! 将概率问题转化为圆心所在的面积! 代码如下: #include<iostream> #include<stdio.h> #include<a ...

  5. 分布式事务的管理--atomikos

    在一些业务场景及技术架构下,跨库的事务时不可避免的,这时候如何统一管理事务,保证事务的强一致性是整个系统稳定.可用基石.一些中间件如tuxedo.cics就是凭借这个能力占据了金融.电信.银行等很大的 ...

  6. POJ1860——Currency Exchange(BellmanFord算法求最短路)

    Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...

  7. Firefox Security Toolkit 安装

    目的: 下载Firefox Security Toolkit加载到浏览器里,增强渗透测试的工具利用. 兼容性: 目前仅支持Linux/Unix环境(可在kali上安装使用). 下载安装: wget h ...

  8. python学习笔记三--字典

    一.字典: 1. 不是序列,是一种映射, 键 :值的映射关系. 2. 没有顺序和位置的概念,只是把值存到对应的键里面. 3. 通过健而不是通过偏移量来读取 4. 任意对象的无序集合 5. 可变长,异构 ...

  9. IL指令集(转)

    名称 说明 Add 将两个值相加并将结果推送到计算堆栈上. Add.Ovf 将两个整数相加,执行溢出检查,并且将结果推送到计算堆栈上. Add.Ovf.Un 将两个无符号整数值相加,执行溢出检查,并且 ...

  10. chrome和火狐获取资源

    获取网站数据: chrome下获取网站数据可以用如下方式去获取: 而火狐则可以按以下方式获取: 在该目录下找到你想要的数据. 获取本地的数据: chrome下获取本地的数据: firefox下获取本地 ...