Codeforces Round #334 (Div. 2) D. Moodular Arithmetic

题意是告诉这么个函数:,以及相关定义域. ,输入p,k,问可以找出多少函数满足条件

题解:Now assume that k ≥ 2, and let m be the least positive integer such that This is called the \emph{order} of First, plug in x = 0 to find that as p is prime, and . Now for some integer , choose a value for f(n). Given this value, we can easily show that just by plugging in x = ki - 1n into the functional equation and using induction. Note that the numbers n, kn, k2n, ..., km - 1n are distinct , since m is the smallest number such that . Therefore, if we choose the value of f(n), we get the value of m numbers (). Therefore, if we choose f(n) of integers n, we can get the value of all p - 1 nonzero integers. Since f(n) can be chosen in p ways for each of the integers, the answer is .   经过这一系列推导得出这个答案。。。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <queue>
#include <map>
#include <stack>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 1000010
#define MOD 1000000007
char s[maxn];
long long p,k;
long long mod_pow(long long a,long long b,long long p)
{
    long long ans = 1;
    while(b)
    {
        if(b&1)
            ans *= a;
        ans %= p;
        b >>= 1;
        a *= a;
        a %= p;
    }
    return ans;
}
int main()
{
	int t;
	//scanf("%d",&t);
	while(scanf("%I64d%I64d",&p,&k) != EOF)
    {
        if(k == 0)
            printf("%I64d\n",mod_pow(p,p-1,MOD));
        else if(k == 1)
            printf("%I64d\n",mod_pow(p,p,MOD));
        else
        {
            int m = 0;
            long long ans = 1;
            while(1)
            {
                ans *= k;
                ans %= p;
                m++;
                if(ans == 1)
                    break;
            }
            printf("%I64d\n",mod_pow(p,(p-1)/m,MOD));
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值