zoukankan      html  css  js  c++  java
  • geronimo

    http://192.168.102.138/JudgeOnline/problem.php?cid=1279&pid=0

    知识点:1.碰到mod就要留个心眼(什么除啊减啊这些东西可能不能直接mod)

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    int n,mod;
    int f[500100];
    int vis[500100],v[500100];
    int cnt = 0;
    int gcd(int x,int y)
    {
        if(x % y == 0)return y;
        else return gcd(y,x % y);
    }
    int qpow(int x,int t)
    {
        int tans = x,ret = 1;
        while(t)
        {
            if(t&1)ret *= tans,ret %= mod;
            tans *= tans;
            tans %= mod;
            t >>= 1;
        }
        return ret % mod;
    }
    signed main()
    {
        scanf("%lld%lld",&n,&mod);
        for(int i = 1;i <= n;i++)
            scanf("%lld",&f[i]);
        for(int i = 1;i <= n;i++)
        {
            if(f[i] == i)continue;
            if(!vis[i])
            {
                vis[i] = 1;
                int d = 1;
                int t = f[i];
                while(t != i)
                {
                    d++;
                    vis[t] = 1;
                    t = f[t];
                }
                v[++cnt] = d;
            }
        }
        v[0] = 0;
        int pri = 1;
        for(int i = 1;i <= cnt;i++)
        {
            pri *= v[i];
            pri %= mod;
        }
        for(int i = 2;i <= cnt;i++)
        {
            pri *= qpow(gcd(v[i],v[i - 1]),mod - 2);
            pri %= mod;
        }
        printf("%lld",pri);
        return 0;
    }//这是假代码,只能处理mod为质数的情况
  • 相关阅读:
    hdu1814 Peaceful Commission 2-SAT
    上传下载文件
    文件下载类
    文件操作类
    MD5加密帮助类
    加密解密类
    发送邮件函数
    DataTable 分页
    服务器缓存帮助类
    Cookie帮助类
  • 原文地址:https://www.cnblogs.com/xyj1/p/13723590.html
Copyright © 2011-2022 走看看