結果

問題 No.719 Coprime
コンテスト
ユーザー 王源成
提出日時 2025-12-21 20:48:48
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 9 ms / 3,000 ms
コード長 1,032 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,869 ms
コンパイル使用メモリ 197,968 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-21 20:48:52
合計ジャッジ時間 4,201 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1300,T=12;
const int p[]={2,3,5,7,11,13,17,19,23,29,31,37};
int n,ans=0;
int s[N];
vector<int> sy[N];
int f[1<<12],g[1<<12];
signed main(){
    //freopen("score.in","r",stdin);
    //freopen("score.out","w",stdout);
    cin>>n;
    for(int i=2;i<=n;i++){
        int t=i;
        for(int j=0;j<T;j++){
            if(t%p[j]==0){
                s[i]|=(1<<j);
                while(t%p[j]==0) t/=p[j];
            }
        }
        sy[t].push_back(i);
    }
    for(int x:sy[1]){
        for(int i=(1<<T)-1;i>=0;i--){
            if(s[x]&i) continue;
            f[s[x]|i]=max(f[s[x]|i],f[i]+x);
        }
    }
    for(int i=2;i<=n;i++){
        for(int j=0;j<(1<<T);j++) g[j]=f[j];
        for(int x:sy[i]){
            for(int j=(1<<T)-1;j>=0;j--){
                if(s[x]&j) continue;
                f[s[x]|j]=max(f[s[x]|j],g[j]+x);
            }
        }
    }
    for(int i=0;i<(1<<T);i++)ans=max(ans,f[i]);
    cout<<ans<<"\n";
    return 0;
}
0