結果

問題 No.826 連絡網
ユーザー _____TAB_____
提出日時 2019-05-03 22:13:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 549 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 71,776 KB
最終ジャッジ日時 2025-01-07 03:26:25
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int minimum_prime_factor(int x){
  for(int i = 2; i*i <= x; ++i){
    if(x%i) continue;
    return i;
  }
  return x;
}

int main(){
  int N, P;
  cin >> N >> P;
  if(P == 1){
    cout << 1 << endl;
    return 0;
  }
  int ans = 0;
  vector<long long> D(N);
  for(int i = 0; i < N; ++i){
    D[i] = minimum_prime_factor(i+1);
  }
  long long m = D[P-1];
  for(int i = 1; i < N; ++i){
    if(D[i] == m or D[i]*m <= N){
      ++ans;
      m = min(D[i],m);
    }
  }
  cout << ans << endl;
}
0