zoukankan      html  css  js  c++  java
  • codeforce 603B

    题意:给出方程 f(kx%p)=kf(x)%p ,f:A->B,不同的映射函数f有几种,其中f,A,B值域为{0,1,2..p-1},p为素数(除了2),k为小于p的一个常数。

    思路:明显是求循环节的。

    首先分析特殊情况:

    k==0:f(x)=0.其余f(x)为值域中任何一个值,所以有p^(p-1)种;

    k==1:f(x)=x.所以有p^(p)种;

    其他:

    若已知f(x)=n,则f(kx),f(k^2*x),f(k^3*x),...f(k^m*x)的值都求的出来;f(k^2*x%p)=k^2*f(x)%p=k*f(kx)%p;以此内推

    当m到某个值时一定循环了,k^m=(同余)1%p;

    转化成求m;

    p^((p-1)/m);

     1 #include <bits/stdc++.h>
     2 #include<cmath>
     3 #include <iostream>
     4 #include <cstdio>
     5 #include <algorithm>
     6 #include <cstring>
     7 #include <cmath>
     8 typedef long long ll;
     9 using namespace std;
    10 
    11 const ll mod= 1e9+7;
    12 
    13 ll pow1(ll x,ll n)
    14 {
    15     ll ret =1;
    16     ll num =x;
    17     while(n)
    18     {
    19         if(n&1)
    20         {
    21             ret*=num;
    22             ret%=mod;
    23         }
    24         num*=num;
    25         num%=mod;
    26         n>>=1;
    27     }
    28     return ret;
    29 }
    30 int main()
    31 {
    32     int p,k;
    33     while(~scanf("%d%d",&p,&k))
    34     {
    35         if(k==0)
    36         {
    37             printf("%64d
    ",pow1(p,p-1));
    38             continue;
    39         }
    40         if(k==1)
    41         {
    42             printf("%64d
    ",pow1(p,p));
    43             continue;
    44         }
    45         ll temp;
    46         temp=k;
    47         int m;
    48         for( m=1;m<p;m++)
    49         {
    50             if(temp==1)
    51             {
    52                 break;
    53             }
    54             temp*=k;
    55             temp%=p;
    56         }
    57         int x=ceil((p-1)*1.0/m);
    58         printf("%64d
    ",pow1(p,x));
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    Unity Ioc框架简单例子
    Newtonsoft.Json.Linq
    Quartz.net
    AngularJS
    Zookeeper
    mysql 游标CURSOR
    mysql 存储过程 CONCAT 字符串拼接
    MD5Util
    生成缩略图
    Asp.net MVC 基于Area的路由映射
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5016416.html
Copyright © 2011-2022 走看看