zoukankan      html  css  js  c++  java
  • 【2018 CCPC网络赛】1003

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6440

    这题主要是理解题意;

    题意:定义一个加法和乘法,使得 (m+n)p = mp+np;

       其中给定 p 为素数,m,n 为小于p的数;

       费马小定理:am-1 ≡ 1(mod p); 

       故有 a≡ a(mod p), 同理(a+b)m = a+b(mod p) = a+ b;  

       所以原等式恒成立,不需要定义特别的加法和乘法,只需在原来的基础上取模即可;

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 
     5 int T, p;
     6 
     7 int main()
     8 {
     9     scanf("%d",&T);
    10     while(T--)
    11     {
    12         cin>>p;
    13         for(int i=0; i<p; i++) {
    14             for(int j=0; j<p-1; j++) 
    15                 printf("%d ", (i+j)%p);
    16             printf("%d
    ", (i+p-1)%p);
    17         }
    18         for(int i=0; i<p; i++) {
    19             for(int j=0; j<p-1; j++) 
    20                 printf("%d ", i*j%p);
    21             printf("%d
    ", i*(p-1)%p);
    22         }
    23     }
    24     
    25     return 0;
    26 }
  • 相关阅读:
    用python将博客园的文章爬取到本地
    2016.7.9
    2016.7.8
    2016.7.7
    2016.7.5
    2016.7.4
    2016.7.3
    2016.7.2
    2016.6.28
    2016.6.27
  • 原文地址:https://www.cnblogs.com/liubilan/p/9541045.html
Copyright © 2011-2022 走看看