hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造

Posted mountaink

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造相关的知识,希望对你有一定的参考价值。

题目传送门

题目大意:

      给定一个素数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<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 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) ? 
 :  );
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) ? 
 :  );
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,ap?1?a,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=1?1=1. On the other hand, 02=0?0=012=1?1=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 (i?1)+(j?1). The j-th(1jp) integer of (p+i)-th(1ip) line denotes the value of (i?1)?(j?1).
 

 

Sample Input
1 2
 

 

Sample Output
0 1 1 0 0 0 0 1

 































以上是关于hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造的主要内容,如果未能解决你的问题,请参考以下文章

hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造

2018中国大学生程序设计竞赛 - 网络选拔赛 Dream hdu6440 Dream 给出一个(流氓)构造法

2018中国大学生程序设计竞赛 - 网络选拔赛 hdu 6440 Dream 模拟

2018 CCPC网络赛 Dream (费马小定理)

HDU - 6440 Dream 2018中国大学生程序设计竞赛 - 网络选拔赛

2018 CCPC网络赛 Dream&&Find Integer