当前位置:网站首页>HDU 6440 2018 Chinese college student program design network competition
HDU 6440 2018 Chinese college student program design network competition
2022-07-04 19:36:00 【Acacia moon tower】
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;
}
边栏推荐
- socket编程demo二
- 添加命名空间声明
- 牛客小白月赛7 F题
- QT realizes interface sliding switching effect
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
- @transactional滥用导致数据源连接池耗尽问题
- Online text line fixed length fill tool
- Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
- 如何使用Async-Awati异步任務處理代替BackgroundWorker?
- SSL证书续费相关问题详解
猜你喜欢

Opencv functions and methods related to binary threshold processing are summarized for comparison and use
redis分布式锁的8大坑总结梳理

node_ Exporter deployment

Nebula importer data import practice

西门子HMI下载时提示缺少面板映像解决方案

MySQL数据库基本操作-DDL | 黑马程序员

使用canal配合rocketmq监听mysql的binlog日志

The 300th weekly match of leetcode (20220703)

Go microservice (II) - detailed introduction to protobuf

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
随机推荐
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
Introduction to polyfit software
The kth largest element in the array
添加命名空间声明
@transactional滥用导致数据源连接池耗尽问题
2021 合肥市信息学竞赛小学组
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
Don't just learn Oracle and MySQL!
26. 删除有序数组中的重复项 C#解答
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
基于NCF的多模块协同实例
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
YOLOv5s-ShuffleNetV2
Leetcode ransom letter C # answer
《工作、消费主义和新穷人》的微信读书笔记
牛客小白月赛7 谁是神箭手
How test engineers "attack the city" (Part I)
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
HDU 6440 2018中国大学生程序设计网络选拔赛