結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー Udit GuptaUdit Gupta
提出日時 2021-08-27 22:03:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 3,956 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 208,568 KB
実行使用メモリ 169,404 KB
最終ジャッジ日時 2024-11-21 02:28:02
合計ジャッジ時間 10,478 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
167,792 KB
testcase_01 AC 298 ms
168,176 KB
testcase_02 AC 337 ms
168,012 KB
testcase_03 AC 300 ms
167,812 KB
testcase_04 AC 300 ms
169,372 KB
testcase_05 AC 299 ms
167,844 KB
testcase_06 AC 300 ms
168,720 KB
testcase_07 AC 300 ms
169,404 KB
testcase_08 AC 302 ms
168,768 KB
testcase_09 AC 299 ms
168,568 KB
testcase_10 AC 299 ms
167,848 KB
testcase_11 AC 300 ms
168,512 KB
testcase_12 AC 328 ms
167,920 KB
testcase_13 AC 314 ms
168,636 KB
testcase_14 AC 319 ms
168,392 KB
testcase_15 AC 320 ms
168,200 KB
testcase_16 AC 307 ms
168,900 KB
testcase_17 AC 302 ms
169,032 KB
testcase_18 AC 301 ms
169,028 KB
testcase_19 AC 334 ms
169,296 KB
testcase_20 AC 307 ms
168,960 KB
testcase_21 AC 343 ms
168,756 KB
testcase_22 AC 300 ms
168,628 KB
testcase_23 AC 303 ms
168,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*          J  A  I   S  H  R  E  E   R  A  M          */



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

#ifdef LUCTIVUD
#include <buggyBaby.hpp>
pretty:: PrettyPrinter NonIterable;
#define cerr cout
#else
#define _____error_____(...)
#endif

#pragma GCC optimize("O3,unroll-loops,trapv")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,sse4,popcnt,lzcnt")
// #pragma GCC optimize "trapv"






/*  Snips   */


typedef long long lld; typedef unsigned long long llu;

#define  forn(I7, E4) for(lld I7=0ll; I7 < E4; (I7)+=1ll)
#define forn1(I7, E4) for(lld I7=1ll; I7 < E4+1; (I7)+=1ll)
#define        len(v) ((int)((v).size()))
#define        all(x) (x).begin(), (x).end()
#define       rall(x) (x).rbegin(), (x).rend()
#define            f1 first
#define            s2 second



/*  Utils   */


const lld MOD = int(1e9) + 7;
const lld &mod = MOD;

const long double EPS = 1e-6;

const lld inf = 2e18;


struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};



signed pleaseAC(void) {

#ifdef LUCTIVUD
    // auto end_time = std::chrono::high_resolution_clock::now();
    // std::chrono::duration<double> diff = end_time - start_time;
    // cerr << "Finished in : " << diff.count() << "\n";
#endif

    return 0;
}


void IAmJustice(void) {

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout.precision(10); cout << fixed;

#ifdef LUCTIVUD
    // const auto start_time = std::chrono::high_resolution_clock::now();
    freopen("/home/luctivud/CPPractice/IO/Zinput.txt", "r", stdin);
    freopen("/home/luctivud/CPPractice/IO/Zoutput.txt", "w", stdout);
#endif

    return;
}








/* This part should be outside the main in global paradigm. */

const long long MAXN = (lld)(1e7) + 1ll; // MAXN Size

vector<long long >isPrime(MAXN , true); // checkIfPrime
vector<long long >prime_numbers; // List of prime numbers
vector<long long >smallest_prime_factor(MAXN); // smallest_prime_factor of a number


void manipulated_seive() {
    isPrime[0] = isPrime[1] = false ;
    
    prime_numbers.push_back(2);
    smallest_prime_factor[2] = 2ll;

    for (long long int i=4; i < MAXN ; i+=2) {
        isPrime[i] = false;
        smallest_prime_factor[i] = 2ll;
    }

    for (long long int i = 3; i < MAXN ; i+=2) {
        if (isPrime[i]) {
            prime_numbers.push_back(i);
            smallest_prime_factor[i] = i;
        }

        for (long long int j = 0; j < (int)prime_numbers.size() && i * prime_numbers[j] < MAXN && prime_numbers[j] <= smallest_prime_factor[i]; j++) {
            isPrime[i * prime_numbers[j]] = false;
            smallest_prime_factor[i * prime_numbers[j]] = prime_numbers[j] ;
        }
    }
}


/* This should be called inside main. */
    










/*:::::::::::::::::::::: LOGIC :::::::::::::::::::::::::*/





void solveEachTest(int _TestCase) {
    // cout << "Case #" << _TestCase << ": ";
    lld a, b; cin >> a >> b;

    lld ans = 0ll;
    for (lld i = a; i <= b; i++) {
        for (lld j = i; j <= b; j++) {
            if (abs(i - j) > 2) break;
            lld num = ((j * (j + 1)) - (i * (i - 1))) / 2;
            if (isPrime[num]) {
                ans += 1;
            }
        }
    }

    cout << ans;

    return;
}



/*:::::::::::::::::::::/LOGIC:::::::::::::::::::::::::*/


signed main() {

    IAmJustice();
    manipulated_seive();
    int _T0T4 = 1;
    // cin >> _T0T4;

    for (int _TestCase = 1; _TestCase <= _T0T4; _TestCase++) {
        solveEachTest(_TestCase);
        cout << "\n";
    }

    return pleaseAC();
}




/*  ~~
    .?.?.?.
*/
0