zoukankan      html  css  js  c++  java
  • hello 2019 D

    一开始sb了考虑总的因子疯狂T,做题太少了。。。没意识到会有辣么多因子。。。

    神仙说1e9以内的最多的就有800个因子的了。。。

    然后我们可以考虑质因子

    我觉得已经说得很明白了。。。

    唔逆元好像exgcd比费马小定理预处理快?

    en...

     1 #include <bits/stdc++.h>
     2 #define mk(a,b) make_pair(a,b)
     3 #define pii pair<int,int>
     4 using namespace std;
     5 typedef long long ll;
     6 const ll mod = 1e9+7;
     7 const int N = 3e7+1;
     8 ll qpow(ll a,ll x){
     9     ll res = 1;
    10     while (x){
    11         if(x&1)
    12             res=(res*a)%mod;
    13         a=(a*a)%mod;
    14         x/=2;
    15     }
    16     return res;
    17 }
    18 void exgcd(ll a,ll b,ll& d,ll& x,ll& y) {
    19     if (!b) {
    20         d = a;
    21         x = 1;
    22         y = 0;
    23     } else {
    24         exgcd(b, a % b, d, y, x);
    25         y -= x * (a / b);
    26     }
    27 }
    28 ll inv(ll a, ll p) {
    29     ll d, x, y;
    30     exgcd(a, p, d, x, y);
    31     return d == 1 ? (x + p) % p : -1;
    32 }
    33 
    34 ll n,k;
    35 ll dp[55][55][10005];
    36 map<ll,int> mp;
    37 map<ll,int> m;
    38 int main(){
    39     ios::sync_with_stdio(false);
    40     cin>>n>>k;
    41     int id = 0;
    42     for(int i=2;1ll*i*i<=n;i++){
    43         if(n%i==0) {
    44             m[i] = id;
    45             while (n%i==0){
    46                 mp[i]++;
    47                 n/=i;
    48             }
    49             dp[id][0][0]=1;
    50             for(int j=1;j<=mp[i];j++)
    51                 dp[id][j][0]=dp[id][j-1][0]*i%mod;
    52             id++;
    53         }
    54     }
    55     if(n!=1){
    56         m[n]=id;
    57         dp[id][1][0]=n;
    58         dp[id][0][0]=1;
    59         mp[n]++;
    60         id++;
    61     }
    62     for(int i=1;i<=k;i++){
    63         for(auto p:mp){
    64             int ind = m[p.first];
    65             ll num = p.first;
    66             for(int j=0;j<=p.second;j++){//每个次幂
    67                 for(int k=0;k<=j;k++){
    68                     dp[ind][j][i]+=dp[ind][k][i-1];
    69                 }
    70                 dp[ind][j][i]%=mod;
    71                 dp[ind][j][i]=dp[ind][j][i]*inv(j+1,mod)%mod;
    72             }
    73         }
    74     }
    75     ll ans = 1;
    76     for(auto p:mp){
    77         ans=(ans*dp[m[p.first]][p.second][k]%mod);
    78     }
    79     cout<<ans<<endl;
    80 }
    View Code
  • 相关阅读:
    Leetcode——栈和队列(3)
    Leetcode——栈和队列(2)
    java——面试题 基础(上)
    Leetcode——栈和队列(1)
    LeetCode——动态规划整理(2)
    LeetCode——动态规划整理(1)
    计算机网络——数据中心(下)
    计算机网络——数据中心(上)
    计算机网络——HTTP(下)
    计算机网络——HTTP(上)
  • 原文地址:https://www.cnblogs.com/MXang/p/10224674.html
Copyright © 2011-2022 走看看