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. ...
随机推荐
- 对数组名取地址 a[ ],&a
C语言规定,数组名代表数组的首地址,也就是第0号元素的地址.所以a==&a[0] 但对数组名取地址时却要注意了,在理解“对数组名取地址”这一表达式的含义时一定要记住:数组名是“数组”这种变量的 ...
- ImageView 的 ScaleType
/** * Options for scaling the bounds of an image to the bounds of this view. 将一个图片的边界缩放到这个view边界的几种选 ...
- Java开源中文分词类库
IKAnalyzer IKAnalyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包.从2006年12月推出1.0版开始,IKAnalyzer已经推出了3个大版本.最初,它是以开 ...
- Group Layout
----------------siwuxie095 将根面板 contentPane 的布局切换为 Group Layout Grou ...
- __get(),__set(),__isset(),__unset()
__get(),__set(),__isset(),__unset() 在给不可访问属性赋值时,__set()会被调用读取不可访问属性的值时,__get()会被调用 当对不可访问属性调用isset() ...
- Java3D读取3DMax模型并实现鼠标拖拽、旋转、滚轮缩放等功能
/**-------------------------------------------------代码区--------------------------------------------- ...
- 高性能MySQL笔记-第5章Indexing for High Performance-001B-Tree indexes(B+Tree)
一. 1.什么是B-Tree indexes? The general idea of a B-Tree is that all the values are stored in order, and ...
- 数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation 标签: 图像处理MATLAB
实验要求: Zooming and Shrinking Images by Bilinear Interpolation Objective To manipulate another techniq ...
- 3.文档视图:从gui分割状态
为了解决一个类实现所有功能的缺陷,我们把application分为2个部分.一个部分业务逻辑,一个部分视觉渲染和交互.这2个类在学术上被称为document view 或者 model delegat ...
- .net 索引器
索引器允许类或结构的实例就像数组一样进行索引. 索引器类似于属性,不同之处在于它们的访问器采用参数. 在下面的示例中,定义了一个泛型类,并为其提供了简单的 get 和 set 访问器方法(作为分配和检 ...