2018中国大学生程序设计竞赛 - 网络选拔赛 1003 Dream(hdu 6440)(费马小定理)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yz467796454/article/details/82112890

题目链接hdu 6440 Dream

Sample Input
1
2
 

Sample Output
0 1
1 0
0 0
0 1

题意:重新定义+和*运算,要求小于p的m和n,满足(m+n)^p=m^p+n^p,p为素数 

思路:题意比较难懂,但是如果想到了费马小定理,代码是很简单的

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int p;
		scanf("%d",&p);
		for(int i=1;i<=p;i++){
			for(int j=1;j<=p;j++){
				printf("%d ",((i-1)+(j-1))%p);
			}
			printf("\n");
		}
		for(int i=1;i<=p;i++){
			for(int j=1;j<=p;j++){
				printf("%d ",((i-1)*(j-1))%p);
			}
			printf("\n");
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/yz467796454/article/details/82112890
今日推荐