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. ...
随机推荐
- Android Notification通知
/** * 在状态栏显示通知 */ private void showNotification(){ // 创建一个NotificationManager的引用 NotificationManager ...
- day17-jdbc 1.课程介绍
- Angular04 组件动态地从外部接收值、在组件中使用组件
一.组件从外部接收值 1 修改组件的ts文件,让组件的属性可以从外部接收值 1.1 导入Input注解对象 1.2 在属性变量前面添加 @Input() 注解 1.3 去掉构造器中的属性变量赋值语句 ...
- 客户注册功能,发短信功能分离 通过ActiveMQ实现
客户注册功能,发短信功能分离 通过ActiveMQ 配置链接工厂, 配置session缓存工厂(引入链接工厂) 2.配置模板对象JmsTemplate 引入缓存工厂 指定消息模式(队列,发布和订 ...
- java中public static void main(String[] args)中String[] args代表什么意思?
这是java程序的入口地址,java虚拟机运行程序的时候首先找的就是main方法.跟C语言里面的main()函数的作用是一样的.只有有main()方法的java程序才能够被java虚拟机欲行,可理解为 ...
- 树莓派研究笔记(8)-- 编译lakka v2.1源码
Lakka越玩越觉得强大.如果要是能自己修改一下代码,实现自定义的一些操作就更好了.还可以修复字体文件,修复在部分机器上自动更换Mac地址导致ip变化的问题. 所以我们来尝试编译这个系统.这篇文章几乎 ...
- 发现C#winform编程中不常用的控件(一)<FlowLayoutPanel控件><拆分器控件Splitcontainer >
第一部分:FlowLayoutPanel控件 实现效果: 将FlowLayoutPanel做为导航菜单按钮的容器 以实现 某个菜单按钮不显示时 整体的导航菜单布局不至于"缺憾" 原 ...
- POJ 3411 Paid Roads (状态压缩+BFS)
题意:有n座城市和m(1<=n,m<=10)条路.现在要从城市1到城市n.有些路是要收费的,从a城市到b城市,如果之前到过c城市,那么只要付P的钱, 如果没有去过就付R的钱.求的是最少要花 ...
- Java的get请求-----接口测试
package findyou.Interface; import java.net.HttpURLConnection; import java.net.URL; public class URLC ...
- SQL/T-SQL实例参考-1
CASE ,D.[Score] B_Score ,'Distince'= CASE WHEN C.Score > D.Score THEN C.[Score] - D.[Score] WHEN ...