hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造
题目大意:
给定一个素数p,让你重载加法运算和乘法运算,使(m+n)p=mp+np,并且
存在一个小于p的q,使集合{qk|0<k<p,k∈Z} 等于集合{k|0<k<p,k∈Z}.
然后输出两个矩阵,第一个矩阵输出i+j的值,第二个矩阵输出i*j的值。(题意好难懂,你们怎么都看懂了!!)
思路:
由费马小定理得到,当p是质数的时候,ap-1 ≡ 1(mod p),两边同乘以a,也就是说当ap和a在取模p的时候相等
所以(m+n)p=m+n=mp+np(乘法为x*x%p)。那么将x*y定义成x*y%p,就可以满足这一条件。
而此时第二个约束条件就是原根的性质了。
若g是模p的原根,则 gimod p 的值两两不相同,且,1<g<p , 0<i<p.
而加法就可以随便定义了,只要不和上面的条件冲突(应该是这样),我定义的是 x+y=x。(注意,此时的+已经是一种新的符号了,不能和减法互推,y此时不等于0)。
定理:设是正整数,
是整数,若
模
的阶等于
,则称
为模
的一个原根。
假设一个数对于模
来说是原根,那么
的结果两两不同,且有
,那么
可以称为是模
的一个原根,归根到底就是
当且仅当指数为
的时候成立。(这里
是素数)
模有原根的充要条件:
,其中
是奇素数。
#include<cstdio>
#include<iostream>
#include<algorithm>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
ll p;
inline ll mul(ll x, ll y) {
return x * y % p;
}
int main() {
int T;
cin >> T;
while (T--) {
scanf("%lld", &p);
for (int i = ; i < p; i++) {
for (int j = ; j < p; j++) {
printf("%d%c", i, (j == p - ) ? '\n' : ' ');
}
}
for (int i = ; i < p; i++) {
for (int j = ; j < p; j++) {
printf("%lld%c", mul(i, j), (j == p - ) ? '\n' : ' ');
}
}
} }
Dream
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1210 Accepted Submission(s): 357
Special Judge
For instance, (1+4)2=52=25, but 12+42=17≠25. Moreover, 9+16−−−−−√=25−−√=5, which does not equal 3+4=7.
Fortunately, in some cases when p is a prime, the identity
holds true for every pair of non-negative integers m,n which are less than p, with appropriate definitions of addition and multiplication.
You are required to redefine the rules of addition and multiplication so as to make the beginner's dream realized.
Specifically, you need to create your custom addition and multiplication, so that when making calculation with your rules the equation (m+n)p=mp+np is a valid identity for all non-negative integers m,n less than p. Power is defined as
Obviously there exists an extremely simple solution that makes all operation just produce zero. So an extra constraint should be satisfied that there exists an integer q(0<q<p) to make the set {qk|0<k<p,k∈Z} equal to {k|0<k<p,k∈Z}. What's more, the set of non-negative integers less than p ought to be closed under the operation of your definitions.
Hint for sample input and output:
From the table we get 0+1=1, and thus (0+1)2=12=1⋅1=1. On the other hand, 02=0⋅0=0, 12=1⋅1=1, 02+12=0+1=1.
They are the same.
For every case, there is only one line contains an integer p(p<210), described in the problem description above. p is guranteed to be a prime.
The j-th(1≤j≤p) integer of i-th(1≤i≤p) line denotes the value of (i−1)+(j−1). The j-th(1≤j≤p) integer of (p+i)-th(1≤i≤p) line denotes the value of (i−1)⋅(j−1).
2
1 0
0 0
0 1
hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造的更多相关文章
- HDU6440 Dream 2018CCPC网络赛-费马小定理
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 给定一个素数p ...
- HDU6440 Dream(费马小定理+构造) -2018CCPC网络赛1003
题意: 给定素数p,定义p内封闭的加法和乘法,使得$(m+n)^p=m^p+n^p$ 思路: 由费马小定理,p是素数,$a^{p-1}\equiv 1(mod\;p)$ 所以$(m+n)^{p}\eq ...
- 题解报告:hdu 6440 Dream(费马小定理+构造)
解题思路:给定素数p,定义p内封闭的加法和乘法运算(运算封闭的定义:若从某个非空数集中任选两个元素(同一元素可重复选出),选出的这两个元素通过某种(或几种)运算后的得数仍是该数集中的元素,那么,就说该 ...
- 模拟赛 T1 费马小定理+质因数分解+exgcd
求:$a^{bx \%p}\equiv 1(\mod p)$ 的一个可行的 $x$. 根据欧拉定理,我们知道 $a^{\phi(p)}\equiv 1(\mod p)$ 而在 $a^x\equiv 1 ...
- 【2018 ICPC焦作网络赛 G】Give Candies(费马小定理+快速幂取模)
There are N children in kindergarten. Miss Li bought them N candies. To make the process more intere ...
- 【2018 CCPC网络赛】1003 - 费马小定理
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6440 这题主要是理解题意: 题意:定义一个加法和乘法,使得 (m+n)p = mp+np; 其中给定 ...
- 【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies
G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the pro ...
- UVA10200-Prime Time/HDU2161-Primes,例题讲解,牛逼的费马小定理和欧拉函数判素数。
10200 - Prime Time 此题极坑(本菜太弱),鉴定完毕,9遍过. 题意:很简单的求一个区间 ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
随机推荐
- SQL server 2008安装教程
下载SQL server 2008 r2(网上资源很多,这里给出一个:安装) 解压后右键以管理员权限打开set-up 这里可能会出现问题:.net framework 3.5未安装,可以参考 快速安装 ...
- git 本地代码到github(转)
git 本地代码到github 一·什么是gitHub? 官网解释:gitHub是一个让无论处于何地的代码工作者能工作于同一个项目,同一个版本的平台.(GitHub is a code hosti ...
- JS中的!= 、== 、!==、===的用法和区别
与c++中每一种类型都有明确的的定义不同:因JS中var定义存在,未具体区分类型,!=与==不能包含所有的条件,故加入!==与===用法: var num = 1; var str = '1'; va ...
- MSER
1.注释很全的分析:http://blog.csdn.net/zhaocj/article/details/40742191 2.opencv采用的mser实现方法 * 1. the gray ima ...
- USB无线网卡导致耳机电流声很大
今天把许久未用的USB无线网卡插入到电脑中,戴上耳机准备听音乐,发现耳机里面的电流声非常大.回想以前并没有这种状况呀,忽然发现原来是USB无线网卡和耳机都插在前置面板中了,把USB无线网卡插在后置面板 ...
- hdu6357 Hills And Valleys
传送门 题目大意 给定一个序列A,求翻转A中一个区间之后的最长不降子序列的长度即翻转的区间 分析 发现直接枚举翻转的区间的话是无论如何都不行的,于是有一个非常神奇的做法.我们再设一个序列B = {0, ...
- loj10131 暗的连锁
传送门 分析 首先我们知道如果在一棵树上加一条边一定会构成一个环,而删掉环上任意一条边都不改变连通性.我们把这一性质扩展到这个题上不难发现如果一条树边不在任意一个新边构成的环里则删掉这条边之后可以删掉 ...
- spoj14846 Bribe the Prisoners
看来我还是太菜了,这么一道破题做了那么长时间...... 传送门 分析 我首先想到的是用状压dp来转移每一个人是否放走的状态,但是发现复杂度远远不够.于是我们考虑区间dp,dpij表示i到j区间的所有 ...
- PHP中抽象类与接口的区别
PHP中抽象类与接口的区别 抽象类abstract 概念 定义为抽象的类不能被实例化.任何一个类,如果有一个方法是被声明为抽象的,那么这个类就必须被声明为抽象的类. 继承一个抽象类的时候,子类必须定义 ...
- STL源码剖析--迭代器(转)
一.为什么需要traits编程技术 前面说了很多关于traits的光荣事迹,但是却一直没有介绍traits究竟是个什么东西,究竟是用来干什么的?traits在英文解释中就是特性,下面将会引入trait ...