結果

問題 No.1791 Repeat Multiplication
ユーザー fumofumofunifumofumofuni
提出日時 2021-12-21 11:45:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,069 ms / 3,000 ms
コード長 2,674 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 212,864 KB
実行使用メモリ 39,256 KB
最終ジャッジ日時 2023-10-13 19:48:35
合計ジャッジ時間 26,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 196 ms
5,364 KB
testcase_09 AC 180 ms
5,472 KB
testcase_10 AC 170 ms
5,172 KB
testcase_11 AC 158 ms
4,908 KB
testcase_12 AC 93 ms
4,348 KB
testcase_13 AC 1,000 ms
36,556 KB
testcase_14 AC 1,005 ms
37,228 KB
testcase_15 AC 768 ms
28,372 KB
testcase_16 AC 748 ms
27,332 KB
testcase_17 AC 1,040 ms
38,436 KB
testcase_18 AC 858 ms
31,640 KB
testcase_19 AC 975 ms
36,036 KB
testcase_20 AC 798 ms
29,220 KB
testcase_21 AC 969 ms
35,648 KB
testcase_22 AC 1,044 ms
38,296 KB
testcase_23 AC 816 ms
29,844 KB
testcase_24 AC 1,008 ms
37,000 KB
testcase_25 AC 941 ms
34,528 KB
testcase_26 AC 1,023 ms
37,584 KB
testcase_27 AC 863 ms
31,508 KB
testcase_28 AC 1,065 ms
39,172 KB
testcase_29 AC 1,063 ms
39,084 KB
testcase_30 AC 1,063 ms
39,256 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1,065 ms
39,216 KB
testcase_33 AC 1,069 ms
39,140 KB
testcase_34 AC 1,068 ms
39,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


class osak{
    vector<long long> res;
    public:
    vector<long long> prime;
    osak(long long n){//sieve(n),O(N);
        res=vector<long long>(n);
        iota(res.begin(), res.end(), 0);
        for (int i = 2; i*i < n; ++i) {
            if (res[i] < i) continue;
            for (int j = i*i; j < n; j += i)
            if (res[j] == j) res[j] = i;
        }
        for(int i = 2; i < n; ++i){
            if(res[i]==i)prime.emplace_back(i);
        }
    }

    map<long long,long long> factor(int n) {
        map<long long,long long> factor;
        while (n > 1) {
            factor[res[n]]++;
            n /= res[n];
        }
        return factor;
    }

    vector<long long> divisor(int N){//O(div.size())
        map<long long,long long> facs=factor(N);
        vector<long long> ret={1};
        for(auto p:facs){
            ll range=ret.size();
            ll now=1;
            for(int i=0;i<p.se;i++){
                now*=p.fi;
                for(int j=0;j<range;j++){
                    ret.emplace_back(ret[j]*now);
                }
            }
        }
        sort(ret.begin(),ret.end());
        return ret;
    }
};

int main(){
    ll n,q;cin >> n >> q;
    osak os(n+10);
    vl dp(n+1);
    dp[1]=1;
    for(ll i=2;i<=n;i++){
        for(auto p:os.divisor(i)){
            if(p==i)continue;
            dp[i]+=dp[p];
        }
    }
    vl cum(n+1);rep(i,n)cum[i+1]=cum[i]+dp[i+1];
    //rep(i,n+1)cout << dp[i] <<" ";cout << endl;
    //rep(i,n+1)cout << cum[i] <<" ";cout << endl;
    while(q--){
        ll x;cin >> x;
        cout << dp[x]*cum[n/x] <<  endl;
    }
}   
0