Dream

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1014    Accepted Submission(s): 200
Special Judge

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
分析:比赛的时候做出来的队友说的是数论结论题,比赛后我是按照题目意思直接模拟A掉的。。
  根据题目给出的数字p按照题目的意思我们可以得到一个2*p行,p列的矩阵
  其中1<=i<=p,1<=j<=p时:mapn[i][j] = ((i-1)+(j-1))%p
    p+1<=i<=2*p,1<=j<=p时:mapn[i][j] = ((i-1)*(j-1))%p
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = pow(2,10)+10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
const double pi = acos(-1.0);
ll mapn[2*maxn][maxn];
int main() {
ll T, p;
scanf("%lld",&T);
while(T--) {
memset(mapn,0,sizeof(mapn));
scanf("%lld",&p);
for( ll i = 1; i <= 2*p; i ++ ) {
for( ll j = 1; j <= p; j ++ ) {
if( i <= p ) {
mapn[i][j] = ((i-1)+(j-1))%p;
} else {
mapn[i][j] = (i-1)*(j-1)%p;
}
if( j != p ) {
printf("%lld ",mapn[i][j]);
} else {
printf("%lld\n",mapn[i][j]);
}
}
}
}
return 0;
}

  

2018中国大学生程序设计竞赛 - 网络选拔赛 hdu 6440 Dream 模拟的更多相关文章

  1. 2018中国大学生程序设计竞赛 - 网络选拔赛 hdu Tree and Permutation 找规律+求任意两点的最短路

    Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  2. 2018中国大学生程序设计竞赛 - 网络选拔赛 hdu Find Integer 数论

    Find Integer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  3. 2018中国大学生程序设计竞赛 - 网络选拔赛 1001 - Buy and Resell 【优先队列维护最小堆+贪心】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6438 Buy and Resell Time Limit: 2000/1000 MS (Java/O ...

  4. 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...

  5. 2018中国大学生程序设计竞赛 - 网络选拔赛 1009 - Tree and Permutation 【dfs+树上两点距离和】

    Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  6. HDU - 6440 Dream 2018中国大学生程序设计竞赛 - 网络选拔赛

    给定的\(p\)是素数,要求给定一个加法运算表和乘法运算表,使\((m+n)^p = m^p +n^p(0 \leq m,n < p)\). 因为给定的p是素数,根据费马小定理得 \((m+n) ...

  7. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...

  8. 2018中国大学生程序设计竞赛 - 网络选拔赛 Dream hdu6440 Dream 给出一个(流氓)构造法

    http://acm.hdu.edu.cn/showproblem.php?pid=6440 题意:让你重新定义任意一对数的乘法和加法结果(输出乘法口诀表和加法口诀表),使得m^p+n^p==(m+n ...

  9. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...

随机推荐

  1. 浅析java中的语法糖

    概述 编译器是一种计算机程序, 它主要的目的是将便于人编写.阅读.维护的高级计算机语言所写的源代码程序, 翻译为计算机能解读.运行的低阶机器语言的程序, 即可执行文件.而 javac 就是java语言 ...

  2. JAVA并发之阻塞队列浅析

    背景 因为在工作中经常会用到阻塞队列,有的时候还要根据业务场景获取重写阻塞队列中的方法,所以学习一下阻塞队列的实现原理还是很有必要的.(PS:不深入了解的话,很容易使用出错,造成没有技术深度的样子) ...

  3. LFS8.3BOOT引导疑点解决

    LFS系统 的BOOT引导 在LFS书中写到的BOOT引导,时直接将宿主机的BOOT分区挂载当LFS的BOOT分区中,虽然这样也是可以实现BOOT引导的,但是我并不想这样做,所以BOOT引导就变得有些 ...

  4. maven 下载 安装 环境配置

    电脑系统:win10  64位   idea 2019    Java 1.8 1.链接地址,我一般都找官网 http://maven.apache.org/download.cgi 截图:注意mav ...

  5. 后端小白的VUE入门笔记, 前端高能慎入

    因为项目需要前后端分离,后端竟然不用控制view层了,页面的跳转后端不再干涉,(前端的vue经过打包后成了一张index.html) 后端只需要响应给前端json串就ok,其实这不是爽歪歪?但是觉得还 ...

  6. 【Java例题】4.3 3. 使用Gauss消元法求解n元一次方程组的根,

    3. 使用Gauss消元法求解n元一次方程组的根,举例,三元一次方程组:0.729x1+0.81x2+0.9x3=0.6867x1+x2+x3=0.83381.331x1+1.21x2+1.1x3=1 ...

  7. [Spring cloud 一步步实现广告系统] 14. 全量索引代码实现

    上一节我们实现了索引基本操作的类以及索引缓存工具类,本小节我们开始实现加载全量索引数据,在加载全量索引数据之前,我们需要先将数据库中的表数据导出到一份文件中.Let's code. 1.首先定义一个常 ...

  8. .netcore持续集成测试篇之开篇简介及Xunit基本使用

    系列目录 为了支持跨平台,微软为.net平台提供了.net core test sdk,这样第三方测试框架诸如Nunit,Xunit等只需要按照sdk提供的api规范进行开发便可以被dotnet cl ...

  9. 微服务与网关技术(SIA-GateWay)

    一.背景 软件架构,总是在不断的演进中... 把时间退回到二十年之前,当时企业级领域研发主要推崇的还是C/S模式,PB.Delphi这样的开发软件是企业应用开发的主流.随着时间的推移,基于浏览器的B/ ...

  10. Vue 路由模块化配置

    博客地址:https://ainyi.com/77 企业运营后台页面很多,路由如若不区分模块化配置,所有路由挤在同一个文件将不好维护,所以路由的配置也要模块化 分享两个解决方案 -- Vue 路由配置 ...