結果

問題 No.2318 Phys Bone Maker
ユーザー planesplanes
提出日時 2023-05-26 22:27:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,151 ms / 3,000 ms
コード長 1,511 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 179,352 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-26 12:29:47
合計ジャッジ時間 11,727 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,380 KB
testcase_01 AC 12 ms
4,384 KB
testcase_02 AC 1,151 ms
4,428 KB
testcase_03 AC 16 ms
4,384 KB
testcase_04 AC 18 ms
4,384 KB
testcase_05 AC 18 ms
4,380 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 23 ms
4,384 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 21 ms
4,444 KB
testcase_16 AC 20 ms
4,440 KB
testcase_17 AC 24 ms
4,376 KB
testcase_18 AC 23 ms
4,380 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 AC 19 ms
4,380 KB
testcase_21 AC 18 ms
4,376 KB
testcase_22 AC 17 ms
4,384 KB
testcase_23 AC 17 ms
4,380 KB
testcase_24 AC 21 ms
4,376 KB
testcase_25 AC 20 ms
4,384 KB
testcase_26 AC 21 ms
4,380 KB
testcase_27 AC 21 ms
4,384 KB
testcase_28 AC 17 ms
4,380 KB
testcase_29 AC 17 ms
4,380 KB
testcase_30 AC 16 ms
4,376 KB
testcase_31 AC 22 ms
4,484 KB
testcase_32 AC 21 ms
4,384 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 20 ms
4,376 KB
testcase_35 AC 121 ms
4,380 KB
testcase_36 AC 510 ms
4,396 KB
testcase_37 AC 539 ms
4,384 KB
testcase_38 AC 589 ms
4,376 KB
testcase_39 AC 802 ms
4,380 KB
testcase_40 AC 839 ms
4,512 KB
testcase_41 AC 905 ms
4,472 KB
testcase_42 AC 993 ms
4,396 KB
testcase_43 AC 25 ms
4,380 KB
testcase_44 AC 185 ms
4,380 KB
testcase_45 AC 170 ms
4,380 KB
testcase_46 AC 1,075 ms
4,376 KB
testcase_47 AC 24 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;
const ll mod=998244353;

vector<ll> yaku,nso;
ll N;
map<ll,ll> S;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

ll solve(ll k) {
  if(k==N) return 1;
if(S.count(k)) return S[k];

  ll ans=0;
  for(ll i=0;i<(ll)yaku.size();i++) {
    if(yaku[i]%k==0&&yaku[i]>k) {
      ll d=yaku[i]/GCD(yaku[i],k);
      ll s=1;
      for(auto x:nso) {
        if(k%x==0&&d%x!=0) {
          ll t=k;
          ll count=1;
          while(t%x==0) {
            t/=x;
            count++;
          }
          s*=count;
          s%=mod;
        }
      }

  ans+=s*solve(yaku[i])%mod;
  ans%=mod;
    }
  }
  S[k]=ans;
  return ans;
}


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>N;

yaku=vector<ll> (0);

for(ll i=1;i<=sqrt(N);i++) {
  if(N%i==0) {
    ll a=N/i;
  if(i!=a) {
    yaku.push_back(a);
    yaku.push_back(i);
  }
  else yaku.push_back(i);
  }
}

sort(all(yaku));

ll ma=1000000+100;
vector<bool> note(ma,false);
vector<ll> so(0);

for(ll i=2;i<ma;i++) {
  if(note[i]) continue;
so.push_back(i);
for(ll j=1;j*i<ma;j++) note[j*i]=true;
}

nso=vector<ll> (0);
ll n=N;
for(auto x:so) {
  if(n%x==0) nso.push_back(x);
  while(n%x==0) n/=x;
}

if(n>1) {
  nso.push_back(n);
}



ll ans=solve(1);
if(ans<0) ans+=mod;
cout<<ans<<endl;
}



0