結果
| 問題 | No.3296 81-like number | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2025-10-06 17:18:13 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,131 bytes | 
| コンパイル時間 | 679 ms | 
| コンパイル使用メモリ | 63,864 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-10-06 17:18:15 | 
| 合計ジャッジ時間 | 1,825 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 15 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |   scanf("%lld", &n);
      |   ~~~~~^~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 3296.cc:  No.3296 81-like number - yukicoder
 */
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_P = 100000 + 50;
/* typedef */
using ll = long long;
using vb = vector<bool>;
using vi = vector<int>;
/* global variables */
vb primes;
vi pnums;
/* subroutines */
int gen_primes(int maxp) {
  primes.assign(maxp + 1, true);
  primes[0] = primes[1] = false;
  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums.push_back(p);
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums.push_back(p);
  return (int)pnums.size();
}
ll powi(ll a, int e) {
  ll p = 1;
  while (e > 0) {
    if (e & 1) p *= a;
    a *= a;
    e >>= 1;
  }
  return p;
}
/* main */
int main() {
  gen_primes(MAX_P);
  
  ll n;
  scanf("%lld", &n);
  ll sum = 0;
  for (auto p: pnums) {
    if ((ll)p * p > n) break;
    int e = 0;
    for (ll m = n; m >= p; e++, m /= p);
    sum += (powi(p, e - 1) - 1) / (p - 1) * p * p;
  }
  printf("%lld\n", sum);
  
  return 0;
}
            
            
            
        