博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造
阅读量:5145 次
发布时间:2019-06-13

本文共 3420 字,大约阅读时间需要 11 分钟。

题目大意:

      给定一个素数p,让你重载加法运算和乘法运算,使(m+n)p=mp+np,并且

存在一个小于p的q,使集合{

qk|0<k<p,kZ} 等于集合{
k|0<k<p,kZ}

然后输出两个矩阵,第一个矩阵输出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)。

 

      定理:设是正整数,是整数,若的阶等于,则称为模的一个原根。

      假设一个数对于模来说是原根,那么的结果两两不同,且有,那么可以称为是模的一个原根,归根到底就是当且仅当指数为的时候成立。(这里是素数)

 

       模有原根的充要条件:,其中是奇素数。

 

1 #include
2 #include
3 #include
4 #define CLR(a,b) memset((a),(b),sizeof((a))) 5 using namespace std; 6 typedef long long ll; 7 ll p; 8 inline ll mul(ll x, ll y) { 9 return x * y % p;10 }11 int main() {12 int T;13 cin >> T;14 while (T--) {15 scanf("%lld", &p);16 for (int i = 0; i < p; i++) {17 for (int j = 0; j < p; j++) {18 printf("%d%c", i, (j == p - 1) ? '\n' : ' ');19 }20 }21 for (int i = 0; i < p; i++) {22 for (int j = 0; j < p; j++) {23 printf("%lld%c", mul(i, j), (j == p - 1) ? '\n' : ' ');24 }25 }26 }27 28 }

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

Problem Description
Freshmen frequently make an error in computing the power of a sum of real numbers, which usually origins from an incorrect equation 
(m+n)p=mp+np, where m,n,p are real numbers. Let's call it ``Beginner's Dream''.
For instance, (1+4)2=52=25, but 12+42=1725. Moreover, 9+16−−−−−√=25−−√=5, which does not equal 3+4=7
Fortunately, in some cases when p is a prime, the identity
(m+n)p=mp+np
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
ap={
1,ap1a,p=0p>0
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,kZ}
 equal to {
k|0<k<p,kZ}
. What's more, the set of non-negative integers less than p ought to be closed under the operation of your definitions.
Hint
Hint for sample input and output:
From the table we get 
0+1=1, and thus (0+1)2=12=11=1. On the other hand, 02=00=012=11=102+12=0+1=1.
They are the same.
 

 

Input
The first line of the input contains an positive integer 
T(T30) indicating the number of test cases.
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.
 

 

Output
For each test case, you should print 
2p lines of p integers.
The j-th(1jp) integer of i-th(1ip) line denotes the value of (i1)+(j1). The j-th(1jp) integer of (p+i)-th(1ip) line denotes the value of (i1)(j1).
 

 

Sample Input
1 2
 

 

Sample Output
0 1 1 0 0 0 0 1

 

转载于:https://www.cnblogs.com/mountaink/p/9545441.html

你可能感兴趣的文章
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
LibSVM for Python 使用
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
CSS属性值currentColor
查看>>
java可重入锁reentrantlock
查看>>
浅谈卷积神经网络及matlab实现
查看>>
解决ajax请求cors跨域问题
查看>>
《收获,不止Oracle》pdf
查看>>
LinkedList<E>源码分析
查看>>
Real-Time Rendering 笔记
查看>>
如何理解HTML结构的语义化
查看>>
Activity之间的跳转:
查看>>
实验四2
查看>>
Android现学现用第十一天
查看>>
多路复用
查看>>
Python数据可视化之Pygal(雷达图)
查看>>
Java学习笔记--字符串和文件IO
查看>>
转 Silverlight开发历程—(画刷与着色之线性渐变画刷)
查看>>