HDU6440 Dream(费马小定理+构造) -2018CCPC网络赛1003
2024-09-06 16:31:34
题意:
给定素数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 ;
}
最新文章
- DuiLib 源码分析之解析xml类CMarkup &; CMarkupNode 头文件
- web系统架构设计中需要知道的点(前端篇)
- Ionic 入门
- JAVA正则表达式:Pattern类与Matcher类详解
- linux显示-bash-4.2# 问题
- hdu 1061 Rightmost Digit
- Android Recovery的汉化 显示中文
- C语言的指针变量
- pwnable.tw silver_bullet
- SpringCloud(6)---熔断降级理解、Hystrix实战
- Asp.net MVC通过自定义特性实现Action日志记录
- 整理:iOS 短信与电话事件的获取
- Material Design系列第四篇——Defining Shadows and Clipping Views
- ActiveMQ 负载均衡与高可用(转载)
- Angular5 UI post 请求 输出 文件下载
- BZOJ 1499 [NOI2005] 瑰丽华尔兹 | 单调队列优化DP
- MVC 设计模式与三层架构
- 运行MySQL远程连接
- 装饰器1、无参数的装饰器 2、有参数的装饰器 3、装饰器本身带参数的以及如果函数带return结果的情况
- BZOJ 1529 [POI2005]ska Piggy banks(并查集)