結果

問題 No.2260 Adic Sum
ユーザー nagisa5101nagisa5101
提出日時 2023-04-07 21:40:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,954 bytes
コンパイル時間 4,654 ms
コンパイル使用メモリ 266,768 KB
実行使用メモリ 105,600 KB
最終ジャッジ日時 2024-04-15 23:49:36
合計ジャッジ時間 17,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 40 ms
8,448 KB
testcase_15 AC 63 ms
10,368 KB
testcase_16 AC 33 ms
7,808 KB
testcase_17 AC 82 ms
11,136 KB
testcase_18 AC 1,108 ms
61,056 KB
testcase_19 AC 1,220 ms
64,896 KB
testcase_20 AC 838 ms
44,672 KB
testcase_21 AC 859 ms
45,312 KB
testcase_22 AC 669 ms
39,040 KB
testcase_23 AC 340 ms
36,352 KB
testcase_24 AC 1,169 ms
69,760 KB
testcase_25 AC 134 ms
15,232 KB
testcase_26 AC 131 ms
14,976 KB
testcase_27 AC 141 ms
15,744 KB
testcase_28 AC 134 ms
14,976 KB
testcase_29 AC 142 ms
15,232 KB
testcase_30 AC 182 ms
17,024 KB
testcase_31 AC 969 ms
105,472 KB
testcase_32 AC 1,079 ms
105,600 KB
testcase_33 AC 105 ms
16,512 KB
testcase_34 AC 258 ms
37,376 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (int i = n; i < (int)(m); i++)
#define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vvvl=vector<vvl>;
using vld=vector<ld>;
using vvld=vector<vld>;

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

const double PI = acos(-1);
//const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=(1LL<<60);
const int INF2=(1<<30);
//using mint=modint1000000007;
//using mint=modint998244353;

pair<ll,ll> calc(ll n,ll p){
    //nは何回pで割り切れるか?
    //最終的なmodも求める
    ll c=0;
    while((n%p)==0){
        c++;
        n/=p;
    }
    return {c,n};
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll n,p;cin>>n>>p;
    vl cnt(30,0);
    ll M=0;
    ll now=1;
    while(now<1e9){
        now*=p;
        M++;
    }
    vector<vector<map<ll,ll>>> cnt_mod(30,vector<map<ll,ll>>(M));

    rep(i,n){
        ll a;cin>>a;
        auto pp=calc(a,p);
        ll k=pp.first,mod=pp.second;
        //cout<<k<<" "<<mod<<endl;
        now=1;
        rep(j,M){
            now*=p;
            cnt_mod[k][j][mod%now]++;
        }
        cnt[k]++;
    }
    ll ans=0;
    repll(i,30){
        rep2(j,i+1,30)ans+=cnt[i]*cnt[j]*i;
        ans+=cnt[i]*(cnt[i]-1)*i/2;
        rep(j,M){
            for(auto p:cnt_mod[i][j]){
                ll c=p.second;
                ans+=c*(c-1)/2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
0