【2018 CCPC网络赛】1003 - 费马小定理
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6440
这题主要是理解题意;
题意:定义一个加法和乘法,使得 (m+n)p = mp+np;
其中给定 p 为素数,m,n 为小于p的数;
费马小定理:am-1 ≡ 1(mod p);
故有 am ≡ a(mod p), 同理(a+b)m = a+b(mod p) = am + bm ;
所以原等式恒成立,不需要定义特别的加法和乘法,只需在原来的基础上取模即可;
#include<iostream>
#include<cstdio>
using namespace std; int T, p; int main()
{
scanf("%d",&T);
while(T--)
{
cin>>p;
for(int i=; i<p; i++) {
for(int j=; j<p-; j++)
printf("%d ", (i+j)%p);
printf("%d\n", (i+p-)%p);
}
for(int i=; i<p; i++) {
for(int j=; j<p-; j++)
printf("%d ", i*j%p);
printf("%d\n", i*(p-)%p);
}
} return ;
}
【2018 CCPC网络赛】1003 - 费马小定理的更多相关文章
- hdu6440 Dream 2018CCPC网络赛C 费马小定理+构造
题目传送门 题目大意: 给定一个素数p,让你重载加法运算和乘法运算,使(m+n)p=mp+np,并且 存在一个小于p的q,使集合{qk|0<k<p,k∈Z} 等于集合{k|0<k&l ...
- 模拟赛 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 ...
- 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 ...
- 【费马小定理+快速幂取模】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 ...
- HDU6440 Dream 2018CCPC网络赛-费马小定理
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 给定一个素数p ...
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- 2018/7/31-zznu-oj- 2128: 素数检测 -【费马小定理裸应用】
2128: 素数检测 时间限制: 1 Sec 内存限制: 128 MB提交: 84 解决: 32[提交] [状态] [讨论版] [命题人:admin] 题目描述 在算法竞赛中你会遇到各种各样的有关 ...
- UVA10200-Prime Time/HDU2161-Primes,例题讲解,牛逼的费马小定理和欧拉函数判素数。
10200 - Prime Time 此题极坑(本菜太弱),鉴定完毕,9遍过. 题意:很简单的求一个区间 ...
随机推荐
- AndroidManifest.xml文件详解(uses-feature) (转载)
转自:http://blog.csdn.net/think_soft/article/details/7596796 语法(SYNTAX): <uses-featureandroid:name= ...
- PCB 线路铜皮面积(残铜率)计算的实现方法
一个多月没更新博客园了,这里继续分享关于PCB工程相关一些知识,做过PCB工程都知道用使用genesis或incam是可以非常方便的计算得到铜皮面积这个参数[下图],但实际这个软件是通过什么算法计算出 ...
- iOS View
创建: 2018/04/19 完成: 2018/04/20 View的创建 创建 storyboard上操作 与代码连接 ● 目的: 通过代码控制view ● 按住option拖动 View的坐 ...
- 洛谷 - P2578 - 九数码游戏 - bfs
https://www.luogu.org/problemnew/show/P2578 一个挺搞的东西,用康托展开做记忆化搜索可以少一个log的查询. #include <bits/stdc++ ...
- 51nod 1062【水题】
直接打表构造啊 #include <stdio.h> #include <string.h> #include <iostream> using namespace ...
- bzoj 1478: Sgu282 Isomorphism && 1815: [Shoi2006]color 有色图【dfs+polya定理】
参考 https://wenku.baidu.com/view/fee9e9b9bceb19e8b8f6ba7a.html?from=search### 的最后一道例题 首先无向完全图是个若干点的置换 ...
- 定位,标记,Socket通信传输位置
# -*- coding: utf- -*- """ Editor : X-POWER Date : -- Motto : talk is cheap,show me y ...
- iOS NavigationBar 导航栏自定义
1. 设置导航栏NavigationBar的背景颜色: a) setBarTintColor : 设置NagivationBar的颜色 也可以用 : [[UINavigationBar appear ...
- CSS3向上移动的效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- pika消息中间件模块
参考: http://www.rabbitmq.com/tutorials/tutorial-one-python.html http://www.rabbitmq.com/tutorials/tut ...