当前位置:网站首页>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;
}
边栏推荐
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- Don't just learn Oracle and MySQL!
- 指定输出的字符集
- 大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
- Wireshark网络抓包
- ftp、sftp文件传输
- [发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- 整理混乱的头文件,我用include what you use
猜你喜欢

Build your own website (15)

从实时应用角度谈通信总线仲裁机制和网络流控

FPGA时序约束分享01_四大步骤简述

英特尔集成光电研究最新进展推动共封装光学和光互连技术进步

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Summary and sorting of 8 pits of redis distributed lock

PolyFit软件介绍
![[release] a tool for testing WebService and database connection - dbtest v1.0](/img/4e/4154fec22035725d6c7aecd3371b05.jpg)
[release] a tool for testing WebService and database connection - dbtest v1.0

To sort out messy header files, I use include what you use

The 300th weekly match of leetcode (20220703)
随机推荐
问下各位大佬有用过cdc直接mysql to clickhouse的么
The kth largest element in the array
LeetCode第300场周赛(20220703)
Wireshark网络抓包
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
1672. Total assets of the richest customers
Wechat reading notes of "work, consumerism and the new poor"
FPGA时序约束分享01_四大步骤简述
2022健康展,北京健博会,中国健康展,大健康展11月13日
DeFi生态NFT流动性挖矿系统开发搭建
生成XML元素
大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
神经网络物联网平台搭建(物联网平台搭建实战教程)
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
How to use async Awati asynchronous task processing instead of backgroundworker?
SSRS筛选器的IN运算(即包含于)用法
Go microservice (II) - detailed introduction to protobuf
Lm10 cosine wave homeopathic grid strategy
测试工程师如何“攻城”(下)