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<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e5+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int main() {
int T;
scanf("%d", &T);
while(T--){
ll n;
scanf("%I64d", &n);
for(ll i = ; i < n; i++){
for(ll j = ; j < n; j++){
printf("%I64d ", (ll)(i+j)%n);
}
printf("\n");
}
for(ll i = ; i < n; i++){
for(ll j = ; j < n; j++){ printf("%I64d ", (ll)i*j%n);
}
printf("\n");
} }
return ;
}
HDU6440 Dream(费马小定理+构造) -2018CCPC网络赛1003的更多相关文章
- hdu6440 Dream(费马小定理)
保证 当 n^p=n(mod p) 是成立 只要保证n*m=n*m(mod p); #include<bits/stdc++.h> using namespace std; int ma ...
- hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造
题目传送门 题目大意: 给定一个素数p,让你重载加法运算和乘法运算,使(m+n)p=mp+np,并且 存在一个小于p的q,使集合{qk|0<k<p,k∈Z} 等于集合{k|0<k&l ...
- 题解报告:hdu 6440 Dream(费马小定理+构造)
解题思路:给定素数p,定义p内封闭的加法和乘法运算(运算封闭的定义:若从某个非空数集中任选两个元素(同一元素可重复选出),选出的这两个元素通过某种(或几种)运算后的得数仍是该数集中的元素,那么,就说该 ...
- HDU6440(费马小定理)
其实我读题都懵逼--他给出一个素数p,让你设计一种加和乘的运算使得\[(m+n)^p = m^p+n^p\] 答案是设计成%p意义下的加法和乘法,这样:\[(m+n)^p\ \%\ p = m+n\] ...
- HDU6440 Dream 2018CCPC网络赛-费马小定理
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 给定一个素数p ...
- [HDOJ5667]Sequence(矩阵快速幂,费马小定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5667 费马小定理: 假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p). 即 ...
- HDU4704+费马小定理
费马小定理题意:求s1+s2+s3+...+sn;si表示n划分i个数的n的划分的个数,如n=4,则s1=1,s2=3 利用隔板定理可知,就是求(2^n-1)%mod-----Y 现在已知 ...
- 费马小定理&欧拉定理
在p是素数的情况下,对任意整数x都有xp≡x(mod p).这个定理被称作费马小定理其中如果x无法被p整除,我们有xp-1≡1(mod p).利用这条性质,在p是素数的情况下,就很容易求出一个数的逆元 ...
- HDU 4549 (费马小定理+矩阵快速幂+二分快速幂)
M斐波那契数列 Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Statu ...
随机推荐
- realme X2谷歌套件
目前市面上的很多手机是不支持谷歌相关组件的,经过不断的测试成功适配realme X2(真机测试完美适配) 为框架的GMS是用户想要体验整套Google服务不可绕开的一环,Google地图.Play商店 ...
- 量化投资学习笔记07——python知识补漏
看<量化投资:以python为工具>这本书,第一部分是python的基础知识.这一部分略读了,只看我还不知道或不熟的. 定义复数 x = complex(2, 5) #2+5j 也可以直接 ...
- .Net 面试题整理(一)
1.C# 的三大特性? 封装.继承.多态 2.简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在类的内部才可以访问. ...
- Spring中的beanPostProcess的作用
BeanPostProcessor是Spring框架中非常重要的bean之一.贯穿在Spring容器中bean的初始化的整个过程. Spring中的beanpostProcess体系结构如下: 可以看 ...
- Spring(一)开篇
目录 1.Spring 介绍 2.Spring 框架的演变 3.Spring 整体架构 Core Container Data Access/Integration Web AOP Test 最后 1 ...
- struct结构体 重载运算符
struct node{ int x,y,z; }; bool operator<(node a,node b) { if(a.x!=b.x) return a.x<b.x; if(a.y ...
- spring boot 集成apollo 快速指南
目前市面上流行的三大配置中心框架:Spring CLoud Config .Alibaba Nacos 以及携程apollo, 我们相应架构组号召,就使用Apollo吧. Work Flow 简单解释 ...
- phpstorm配置git并解决Terminal 中文乱码(Unicode 编码)的方法
前言:在使用PHPstorm的时候,需要用到terminal,主要还是用这个操作git,但是在使用这个的时候会发现,代码里所有中文都是乱码状态,不利于使用,下面就来看看怎么解决这个问题 一.先在php ...
- MySql 常用时间函数
1.date() 提取日期或日期时间表达式的日期部分 select date(create_time) from blog_article; 2.date_format() select date_f ...
- spring boot 的中文乱码
首先 自检IDEA的编码 配置文件加入设置http tomcat spring.http.encoding.force=true spring.http.encoding.charset=UTF-8 ...