結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー kpinkcat
提出日時 2023-12-11 02:33:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 104,084 KB
最終ジャッジ日時 2025-02-18 10:13:44
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 5
other TLE * 1 -- * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:40: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   30 |             if ((l - max + 1) > 0) ans += (l - max + 1);
      |                                    ~~~~^~~~~~~~~~~~~~~~
main.cpp:17:8: note: ‘ans’ was declared here
   17 |     ll ans;
      |        ^~~

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<bitset>
#include<math.h>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;
using ll = long long;

int main()
{
    ll n, l, max = 0;
    ll ans;
    cin >> n >> l;
    vector<ll> p(l+1, 1);
    p[0] = 0;
    p[1] = 0;
    for (int i = 2; i <= l; i++){
        for (int j = i*2; j <= l; j += i){
            p[j] = 0;
        }
    }
    for (ll i = 2; i*(n-1) <= l; i++){
        if (p[i]) {
            max = i*(n-1);
            if ((l - max + 1) > 0) ans += (l - max + 1);
        }
    }
    cout << ans << endl;
}
0