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. ...
随机推荐
- 使用广播退出打开了多个activity的程序
新建一个父类,在父类里动态注册广播,在这个广播的onrecive方法中结束当前activity,让每个activity继承这个父类,在要关闭的activity中发送广播,搞定 下面是代码 父类 pro ...
- Solr搜索的排序打分规则探讨
使用Solr搭建搜索引擎很容易,但是如何制定合理的打分规则(boost)做排序却是一个很头痛的事情.Solr本身的排序打分规则是继承自Lucene的文本相关度的打分即boost,这一套算法对于通用的提 ...
- JavaScript 的异步和单线程
问题 Q:下面的代码是否能满足sleep效果? var t = true; setTimeout(function(){ t = false; }, 1000); while(t){ } alert( ...
- Win10 VS2013 PCL1.8.1和依赖项VTK8.0.1, QHuall(2.15.2), FLANN1.9.1,Boost1.59.0,Zbil1.2.11和libPNG1.6.34编译安装
编译和安装过程最好使用管理员权限去操作,避免不必要的错误. 一般而言为了区分Debug和Release库,添加输入变量 Name: CMAKE_DEBUG_POSTFIX Type: STRING V ...
- tr td th是什么的缩写
tr是 table row 表格的行 td是table data th是table heading表格标题 ,一般表格第一行的数据都是table heading
- 后台执行UNIX/Linux命令和脚本的五种方法
hiveserver 后台启动 nohup "${HIVE_HOME}"/bin/hive --service hiveserver2 & 1. 使用&符号在后台执 ...
- hdu6357 Hills And Valleys
传送门 题目大意 给定一个序列A,求翻转A中一个区间之后的最长不降子序列的长度即翻转的区间 分析 发现直接枚举翻转的区间的话是无论如何都不行的,于是有一个非常神奇的做法.我们再设一个序列B = {0, ...
- DIY的RPM包怎么签名呢 - 笔记
参考 https://gist.github.com/fernandoaleman/1376720 如果打不开上一个连接,请参考https://www.cnblogs.com/LiuYanYGZ/p/ ...
- ssh远程执行命令使用明文密码
经过不懈的搜索终于找到ssh远程执行命令使用明文密码使用sshpass. 例子: sshpass -p "sequoiadb" ssh root@localhost "l ...
- CodeForces 703C Chris and Road (简单几何)
题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...