当前位置:网站首页>HDU 6440 2018中国大学生程序设计网络选拔赛
HDU 6440 2018中国大学生程序设计网络选拔赛
2022-07-04 17:59:00 【相思明月楼】
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
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int t, p;
scanf("%d", &t);
while(t--) {
scanf("%d", &p);
for(int i = 1; i <= p; i++) {
for(int j = 1; j <= p; j++) {
j==p?printf("%d\n", ((i-1)+(j-1))%p):printf("%d ", ((i-1)+(j-1))%p);
}
}
for(int i = 1; i <= p; i++) {
for(int j = 1; j <= p; j++) {
j==p?printf("%d\n", ((i-1)*(j-1))%p):printf("%d ", ((i-1)*(j-1))%p);
}
}
}
return 0;
}
边栏推荐
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
- 自由小兵儿
- QT realizes interface sliding switching effect
- Nebula Importer 数据导入实践
- 使用canal配合rocketmq监听mysql的binlog日志
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- Shell 编程核心技术《三》
- 用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
- Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
- Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
猜你喜欢
牛客小白月赛7 谁是神箭手
建立自己的网站(15)
自由小兵儿
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
每日一题(2022-07-02)——最低加油次数
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Process of manually encrypt the mass-producing firmware and programming ESP devices
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
升级智能开关,“零火版”、“单火”接线方式差异有多大?
随机推荐
BI技巧丨权限轴
redis分布式锁的8大坑总结梳理
IBM WebSphere MQ retrieving messages
牛客小白月赛7 I 新建 Microsoft Office Word 文档
SSRS筛选器的IN运算(即包含于)用法
性能优化之关键渲染路径
The 300th weekly match of leetcode (20220703)
Unity editor extends C to traverse all pictures in folders and subdirectories
在线SQL转Excel(xls/xlsx)工具
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
Nebula Importer 数据导入实践
Technologie de base de la programmation Shell IV
FPGA时序约束分享01_四大步骤简述
一文掌握数仓中auto analyze的使用
添加命名空间声明
[release] a tool for testing WebService and database connection - dbtest v1.0
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
Leetcode fizzbuzz C # answer