zoukankan      html  css  js  c++  java
  • P5221 Product(欧拉函数)

    P5221 Product(欧拉函数)

    题目描述

    ({ m CYJian})最近闲的玩起了(gcd)。。他想到了一个非常简单而有意思的式子:

    [largeprod_{i=1}^Nprod_{j=1}^Nfrac{lcm(i,j)}{gcd(i,j)} (mod 104857601) ]

    ({ m CYJian})已经算出来这个式子的值了。现在请你帮他验算一下吧。({ m CYJian})只给你(0.2s)的时间哦。

    数据范围

    (1 leq N leq 1000000)

    解题思路

    [large prod_{i=1}^Nprod_{j=1}^Nfrac{lcm(i,j)}{gcd(i,j)}\ large =prod_{i=1}^Nprod_{j=1}^Nfrac{ij}{gcd(i,j)^2}\ large =prod_{i=1}^Nprod_{j=1}^Nij *(prod_{i=1}^Nprod_{j=1}^Ngcd(i,j)^2)^{-1}\ largeprod_{i=1}^Nprod_{j=1}^Ngcd(i,j)^2\ large =prod_{d=1}^Nd^{ 2*sum_{i=1}^{frac Nd}sum_{j=1}^{frac Nd}[gcd(i,j)=1]}\ large =prod_{d=1}^Nd^{ 2*(2*varphi(frac Nd) - 1)}\ ]

    const int N = 1005000;
    const int P = 104857601;
    bool e[N];
    int prime[80000];
    int phi[N], tot, n;
    
    ll fpw(ll x, ll mi) {
    	ll res = 1;
    	while (mi) {
    		if (mi & 1) res = res * x % P;
    		x = x * x % P, mi >>= 1;
    	}
    	return res;
    }
    
    void prework(int N) {
    	for (int i = 2;i <= N; i++) {
    		if (!e[i]) prime[++tot] = i, phi[i] = i - 1;
    		for (int j = 1;j <= tot && prime[j] * i <= N; j++) {
    			int t = prime[j] * i; e[t] = 1;
    			if (i % prime[j] == 0) { phi[t] = phi[i] * prime[j]; break; }
    			phi[t] = phi[i] * (prime[j] - 1);
    		}
    		phi[i] = (phi[i] + phi[i-1]) % (P - 1);
    	}
    }
    
    int main() {
    	read(n); prework(n);
    	ll ans = 1, res = 1;
    	for (int i = 1;i <= n; i++) 
    		res = res * i % P, ans = ans * fpw(i, (2 * phi[n/i] + 1) % (P - 1)) % P;
    	write(fpw(res, 2 * n % (P - 1)) * fpw(ans * ans % P, P - 2) % P);
    	return 0;
    }
    
    
  • 相关阅读:
    chlick 在 blur 之后触发
    屏蔽运营商广告
    script标签清除缓存
    http-equiv 详解
    jqLite
    js 时间戳和转换-转载
    JS数组的常用方法
    js 前端实现文件流下载的几种方式
    解决兼容性的库
    移动端兼容性问题
  • 原文地址:https://www.cnblogs.com/Hs-black/p/13088644.html
Copyright © 2011-2022 走看看