結果

問題 No.3296 81-like number
ユーザー rurun
提出日時 2025-10-05 13:37:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 1,329 ms
コンパイル使用メモリ 195,128 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-05 13:38:39
合計ジャッジ時間 2,181 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;

template<typename T>
T modpow(T a, T b, T mod=(1LL<<60)) {
  T res = 1;
  while (b > 0) {
    if (b&1) (res *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return res;
}

template<typename T>
bool is_prime(T n) {
  if (n <= 1) return false;
  for (T i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return true;
}

int main() {
  lint n;
  cin >> n;
  lint ans = 0;
  for (lint i = 2; i*i <= n; i++) {
  	if (!is_prime(i)) continue;
    for (lint j = 2; ; j++) {
      if (modpow(i, j) <= n) ans += modpow(i, j);
      else break;
    }
  }
  cout << ans << endl;
}
0