zoukankan      html  css  js  c++  java
  • 洛谷P1593 因子和

    (large{题目链接})
    (\)
    (Large extbf{Solution: } large{ 易证一个数N的所有因子和为:left( 1+p^{1}_{1}+p^{2},+ldots +p_{1} ^{c_{1}} ight) + ldots + left( 1+p^{1}_{n}+p^{2}_{n}+ldots +p^{c_m}_{n} ight)=prod limits ^{m}_{i=1}( sum limits ^{c_{i}}_{j=0}left( p_{i} ight) ^{j}。\然后如果用费马小定理求逆元的话,注意p_i mod p如果为1,要特判,因为费马小定理只满足p_i - 1与p互质,然后鬼知道我为什么93。\注意特判a=0。})
    (\)
    (Large extbf{Code: })

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    const int p = 9901;
    
    int sol(int x, int y) {
    	ll a = x % p, ret = 1; ++y;
    	for (; y ; a = (a * a) % p, y >>= 1) if (y & 1) ret = (ret * a) % p;
    	a = (x - 1) % p, y = p - 2, --ret;
    	ll s = 1;
    	for (; y ; a = (a * a) % p, y >>= 1) if (y & 1) s = (s * a) % p;
    	return (ret * s) % p;
    }
    
    int main() {
    	ios::sync_with_stdio(false);
    	int a, b;
    	cin >> a >> b;
    	int t = sqrt(a); ll ans = 1;
    	for (int i = 2; i <= t; ++i) {
    		if (a % i) continue;
    		int cnt = 0;
    		while (!(a % i)) { ++cnt, a /= i; }
    		if (i % p == 1) ans = ans * (cnt + 1) % p;
    		else ans = ans * 1ll * sol(i, cnt * b) % p;
    	}
    	if (a != 1) 
    		if (a % p == 1) ans = ans * (b + 1) % p;
    		else ans = ans * 1ll * sol(a % p, b) % p;
    	printf("%d
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    自学Java0711
    自学Java0710
    自学Java0709
    自学Java0708
    Leetcode刷题集
    网站收集
    674. 最长连续递增序列『简单』
    680. 验证回文字符串 Ⅱ『简单』
    686. 重复叠加字符串匹配『简单』
    693. 交替位二进制数『简单』
  • 原文地址:https://www.cnblogs.com/Miraclys/p/12626114.html
Copyright © 2011-2022 走看看