zoukankan      html  css  js  c++  java
  • HDU6440 Dream 2018CCPC网络赛-费马小定理

    (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦

    Catalog

    Problem:Portal传送门

     原题目描述在最下面。
     给定一个素数p,要求定义一个加法运算表和乘法运算表,使的((m+n)^p=m^p+n^p(0le m,nlt p))成立。

    Solution:

     费马小定理:(a^{p-1} = 1;mod;p)((p)是素数)
     所以 (a^p ;mod; p = a^{p-1} imes a ;mod ;p = a ;mod ;p)
     所以有 ((a+b)^p ; mod;p= a + b ; mod; p = a^p + b ^p ;mod;p)
     因此上式子成立。

    AC_Code:

    #include<bits/stdc++.h>
    #define mme(a,b) memset((a),(b),sizeof((a))) 
    using namespace std;
    typedef unsigned long long LL;
    const int N = 2e5 + 7;
    const int M = 1e5 + 7;
    const int MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    
    int add(int x, int y, int mod) {
        int ret = x + y;
        if(ret >= mod) ret -= mod;
        return ret;
    }
    int multiply(int x, int y, int mod) {
        int ret = x * y;
        if(ret >= mod) ret %= mod;
        return ret;
    }
    int main() {
        int tim, n;
        scanf("%d", &tim);
        while(tim--) {
            scanf("%d", &n);
            for (int i = 0; i < n; i++) {
                printf("%d", i);
                for (int j = 1; j < n; j++) printf(" %d", add(i, j, n));
                puts("");
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++){
                  printf("%d%c", multiply(i, j, n), j == n - 1 ? '
    ' : ' ');
                }
            }
        }
        return 0;
    }
    

    Problem Description:

    这里写图片描述

  • 相关阅读:
    各个控件说明
    html常用
    abp.message
    ABP框架——单表实体流程
    AngularJS $http和$.ajax
    AngularJS ng-if使用
    AngularJS 多级下拉框
    AngularJS 计时器
    AngularJS table循环数据
    Python之待学习记录
  • 原文地址:https://www.cnblogs.com/Cwolf9/p/9535607.html
Copyright © 2011-2022 走看看