結果

問題 No.1791 Repeat Multiplication
ユーザー HIcoderHIcoder
提出日時 2023-07-12 11:25:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 853 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 100,684 KB
最終ジャッジ日時 2025-02-15 10:02:41
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


int main(){
    int N,Q;
    cin>>N>>Q;
    vector<int> x(Q);
    for(int q=0;q<Q;q++){
        cin>>x[q];
    }

    vector<ll> dp(N+1,0);
    dp[1]=1;//末尾が1である者は最初の1とおり
    
    for(int a=1;a<=N;a++){
        for(int b=2*a;b<=N;b+=a){
            dp[b]+=dp[a];
        }
    }

    vector<ll> ans(N+1);
    
    for(int i=1;i<=N;i++){
        
        for(ll k=1;i*k<=N;k++){
            ans[i]+=dp[k]*dp[i];
        }
    }

    for(int q=0;q<Q;q++){
        cout<<ans[x[q]]<<endl;
    }


}
0