• Codeforces 622F The Sum of the k-th Powers(数论)


    题目链接 The Sum of the k-th Powers

    其实我也不懂为什么这么做的……看了无数题解觉得好厉害哇……

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define rep(i, a, b)    for (int i(a); i <= (b); ++i)
     6 #define dec(i, a, b)    for (int i(a); i >= (b); --i)
     7 
     8 const int mod = 1000000007;
     9 const int N   = 1000010;
    10 
    11 int v[N], p[N], f[N], r[N], b[N], c[N], d[N];
    12 int n, m, ret, tmp, tot;
    13 
    14 inline int Pow(int a, int b){
    15     int t = 1;
    16     for (; b; b >>= 1, a = 1LL * a * a % mod)
    17         if (b & 1) t = 1LL * t * a % mod;
    18     return t;
    19 }
    20 
    21 int main(){
    22 
    23     scanf("%d%d", &n, &m); ++m;
    24 
    25     f[1] = 1; 
    26     rep(i, 2, m){
    27         if (!v[i]){
    28             f[i] = Pow(i, m - 1);
    29             p[++tot] = i;
    30         }
    31 
    32         rep(j, 1, tot){
    33             if (i * p[j] > m) break;
    34             v[i * p[j]] = 1;
    35             f[i * p[j]] = 1LL * f[i] * f[p[j]] % mod;
    36             if (i % p[j] == 0) break;
    37         }
    38     }
    39 
    40     rep(i, 2, m) (f[i] += f[i - 1]) %= mod;
    41 
    42     if ((n %= mod) <= m) return 0 * printf("%d
    ", f[n]);
    43 
    44     r[0] = r[1] = 1;
    45     rep(i, 2, m) r[i] = 1LL * (mod - r[mod % i]) * (mod / i) % mod;
    46     rep(i, 2, m) r[i] = 1LL * r[i - 1] * r[i] % mod;
    47     rep(i, 1, m + 1) b[i] = (n - i + 1 + mod) % mod;
    48     
    49     c[0] = d[m + 2] = 1;
    50     rep(i, 1, m + 1) c[i] = 1LL * c[i - 1] * b[i] % mod;
    51     dec(i, m + 1, 1) d[i] = 1LL * d[i + 1] * b[i] % mod;
    52 
    53     rep(i, 0, m){
    54         tmp = 1LL * f[i] * r[m - i] % mod * r[i] % mod * c[i] % mod * d[i + 2] % mod;
    55         if ((m - i) & 1) (ret += mod - tmp) %= mod;
    56         else (ret += tmp) %= mod;
    57     }
    58 
    59     return 0 * printf("%d
    ", ret);
    60 }
  • 相关阅读:
    Uva 12166 Equilibrium Mobile
    2015年7月实习经历以及一些感悟
    让键盘只数字键盘
    保留两位小数且,不四舍五入
    vuex的理解
    点击出现闪烁
    vue 添加样式分几种方法
    数据滞后的坑
    H5防止安卓手机软键盘弹出挤压页面导致变形的方法
    js 为false的几种情况
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/6798469.html
Copyright © 2020-2023  润新知