zoukankan      html  css  js  c++  java
  • Codeforces 258C Little Elephant and LCM

    Little Elephant and LCM

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ull unsigned long long
    using namespace std;
    
    const int N = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1e-8;
    
    int n, tot, tmp = 1, ans, a[N], b[N];
    vector<int> fac[N];
    
    int power(int a, int b) {
        if(!a) return 0;
        int ans = 1;
        while(b) {
            if(b & 1) ans = 1ll * ans * a % mod;
            a = 1ll * a * a % mod; b >>= 1;
        }
        return ans;
    }
    
    int main() {
        for(int i = 1; i < N; i++)
            for(int j = i; j < N; j += i)
                fac[j].push_back(i);
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        sort(a + 1, a + 1 + n);
        for(int i = 1; i <= a[n]; i++, tot = 0, tmp = 1) {
            for(auto& t : fac[i]) b[++tot] = lower_bound(a + 1, a + 1 + n, t) - a;
            for(int i = 1; i < tot; i++) tmp = 1ll * tmp * power(i, b[i + 1] - b[i]) % mod;
            ans = (ans + 1ll * tmp * power(tot, n + 1 - b[tot]) % mod) % mod;
            ans = (ans - 1ll * tmp * power(tot - 1, n + 1 - b[tot]) % mod + mod) % mod;
        }
        printf("%d
    ", ans);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    能量项链
    开学前最后一天信奥赛一本通重刷日记
    重刷信奥赛一本通日记-3
    重刷信奥赛一本通日记-2
    重刷信奥赛一本通日记-1
    第二次考试题解way
    第一次考试题解
    第一次考试感言
    「HNOI2012」矿场搭建
    「HAOI2006」受欢迎的牛
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10390801.html
Copyright © 2011-2022 走看看