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)。

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

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

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

原根博客

 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) ? ‘\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=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

(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,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

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.

Input

The first line of the input contains an positive integer T(T≤30) 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(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).

Sample Input

1
2

Sample Output

0 1
1 0
0 0
0 1

原文地址:https://www.cnblogs.com/mountaink/p/9545441.html

时间: 2024-08-21 15:51:39

hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造的相关文章

HDU6440 Dream 2018CCPC网络赛-费马小定理

目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 ?原题目描述在最下面. ?给定一个素数p,要求定义一个加法运算表和乘法运算表,使的\((m+n)^p=m^p+n^p(0≤m, n<p)\)成立. Solution: ?费马小定理:\(a^{p-1} = 1 mod p(p是素数)\) ?所以 \(a^p \;mod\; p = a^{p-1} \times a \;mod \;p = a

HDU6440 Dream(费马小定理+构造) -2018CCPC网络赛1003

题意: 给定素数p,定义p内封闭的加法和乘法,使得$(m+n)^p=m^p+n^p$ 思路: 由费马小定理,p是素数,$a^{p-1}\equiv 1(mod\;p)$ 所以$(m+n)^{p}\equiv (m+n)(mod\;p)$ $m^{p}\equiv m(mod\;p)$ $n^{p}\equiv n(mod\;p)$ 所以在模意义下,有$(m+n)^p=m^p+n^p$ 代码: #include<iostream> #include<cstdio> #include&

题解报告:hdu 6440 Dream(费马小定理+构造)

解题思路:给定素数p,定义p内封闭的加法和乘法运算(运算封闭的定义:若从某个非空数集中任选两个元素(同一元素可重复选出),选出的这两个元素通过某种(或几种)运算后的得数仍是该数集中的元素,那么,就说该集合对于这种(或几种)运算是封闭的.),使得等式恒成立. 由费马小定理可得,∴,则. ∴在模p的意义下,恒成立,且加法运算与乘法运算封闭. 即乘法运算满足. AC代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 int t,p; 4 in

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

Dream 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

【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies

G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N) and each time a child is inv

hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                         (全题文末) 知识点: 整数n有种和分解方法. 费马小定理:p是质数,若p不能整除a,则 a^(p-1) ≡1(mod p).可利用费马小定理降素数幂. 当m为素数,(m必须是素数才能用费马小定理) a=2时.(a=2只是题中条件,a可以为其他值) mod m =  *      //  k=

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

【Lucas定理/费马小定理/中国剩余定理/扩展欧几里得】[BZOJ 1951] 古代猪文

[Description] 求 [Solution] 容易得到, 所以,重点在怎么求 如果是p-1是个质数,我们可以用sqrt(n)的时间枚举所有d,用Lucas定理分别计算求和即可. 但是我们发现p-1=2*3*4679*35617,并不是一个质数,所以Lucas定理不能用了吗?并不,我们可以算出这个合式分别对2.3.4679.35617的模值,写出四个同余方程,再用孙子定理求解即可.注意特判g==p的情况,此时费马小定理不成立,ans=0. [Code] #include<cmath> #

hdu 4549 (矩阵快速幂+费马小定理)

题意:已知F0=a,F1=b,Fn=Fn-1*Fn-2,给你a,b,n求Fn%1000000007的值 思路:我们试着写几组数 F0=a F1=b F2=a*b F3=a*b2 F4=a2*b3 F5=a3*b5 我们发现a,b的系数其实是斐波那契数列,我们只需用矩阵快速幂求出相应系数就行,但是 这个系数随着增长会特别大,这时我们需要利用费马小定理进行降幂处理 费马小定理 ap-1≡1(mod p) 代码: #include <iostream> #include <cmath>