Submission #67157335


Source Code Expand

Copy
/*
import math
def solve():
try:
L, R = map(int, input().split())
except (IOError, ValueError):
return
if L == R:
print(1)
return
start = L + 1
end = R
found_prime_powers = set()
limit = math.isqrt(end)
primes_upto_limit = []
sieve_primes = [True] * (limit + 1)
if limit >= 0:
sieve_primes[0] = False
if limit >= 1:
sieve_primes[1] = False
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/*
import math

def solve():
    try:
        L, R = map(int, input().split())
    except (IOError, ValueError):
        return
    if L == R:
        print(1)
        return
    start = L + 1
    end = R
    found_prime_powers = set()
    limit = math.isqrt(end)
    primes_upto_limit = []
    sieve_primes = [True] * (limit + 1)
    if limit >= 0:
        sieve_primes[0] = False
    if limit >= 1:
        sieve_primes[1] = False
    for p in range(2, limit + 1):
        if sieve_primes[p]:
            primes_upto_limit.append(p)
            for i in range(p * p, limit + 1, p):
                sieve_primes[i] = False
    for p in primes_upto_limit:
        power = p * p
        while power <= end:
            if power >= start:
                found_prime_powers.add(power)
            if power > end // p:
                break
            power *= p
    is_prime_in_range = [True] * (end - start + 1)
    if start == 1 and len(is_prime_in_range) > 0:
        is_prime_in_range[0] = False
    for p in primes_upto_limit:
        start_val = max(p * p, (start + p - 1) // p * p)
        for j in range(start_val, end + 1, p):
            if j >= start:
                is_prime_in_range[j - start] = False
    for i, is_prime in enumerate(is_prime_in_range):
        if is_prime:
            found_prime_powers.add(start + i)
    print(1 + len(found_prime_powers))


if __name__ == "__main__":
    solve()
*/

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

void solve() {
    long long L, R;
    if (!(cin >> L >> R)) {
        return;
    }

    if (L == R) {
        cout << 1 << endl;
        return;
    }

    long long start = L + 1;
    long long end = R;
    set<long long> found_prime_powers;

    long long limit = (long long)(sqrt(end));
    vector<long long> primes_upto_limit;
    vector<bool> sieve_primes(limit + 1, true);

    if (limit >= 0) sieve_primes[0] = false;
    if (limit >= 1) sieve_primes[1] = false;

    for (long long p = 2; p <= limit; ++p) {
        if (sieve_primes[p]) {
            primes_upto_limit.push_back(p);
            for (long long i = p * p; i <= limit; i += p) {
                sieve_primes[i] = false;
            }
        }
    }

    for (long long p : primes_upto_limit) {
        long long power = p * p;
        while (power <= end) {
            if (power >= start) {
                found_prime_powers.insert(power);
            }
            if (power > end / p) break;
            power *= p;
        }
    }

    vector<bool> is_prime_in_range(end - start + 1, true);
    if (start == 1 && is_prime_in_range.size() > 0) {
        is_prime_in_range[0] = false;
    }

    for (long long p : primes_upto_limit) {
        long long start_val = max(p * p, ((start + p - 1) / p) * p);
        for (long long j = start_val; j <= end; j += p) {
            if (j >= start) {
                is_prime_in_range[j - start] = false;
            }
        }
    }

    for (long long i = 0; i < is_prime_in_range.size(); ++i) {
        if (is_prime_in_range[i]) {
            found_prime_powers.insert(start + i);
        }
    }

    cout << 1 + found_prime_powers.size() << endl;
}

int main() {
    solve();
    return 0;
}

Submission Info

Submission Time
Task E - LCM Sequence
User SqRooti
Language C++ 17 (gcc 12.2)
Score 500
Code Size 3356 Byte
Status AC
Exec Time 180 ms
Memory 35692 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:115:29: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<bool>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  115 |     for (long long i = 0; i < is_prime_in_range.size(); ++i) {
      |                           ~~^~~~~~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 01_random_1_05.txt, 01_random_1_06.txt, 01_random_1_07.txt, 01_random_1_08.txt, 01_random_1_09.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 02_random_2_05.txt, 02_random_2_06.txt, 02_random_2_07.txt, 02_random_2_08.txt, 02_random_2_09.txt, 02_random_2_10.txt, 02_random_2_11.txt, 02_random_2_12.txt, 02_random_2_13.txt, 02_random_2_14.txt, 03_corner_00.txt, 03_corner_01.txt, 03_corner_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3504 KiB
00_sample_01.txt AC 1 ms 3428 KiB
00_sample_02.txt AC 180 ms 25300 KiB
01_random_1_00.txt AC 161 ms 23248 KiB
01_random_1_01.txt AC 149 ms 22420 KiB
01_random_1_02.txt AC 70 ms 13000 KiB
01_random_1_03.txt AC 73 ms 13232 KiB
01_random_1_04.txt AC 176 ms 25072 KiB
01_random_1_05.txt AC 78 ms 12640 KiB
01_random_1_06.txt AC 111 ms 17220 KiB
01_random_1_07.txt AC 41 ms 8400 KiB
01_random_1_08.txt AC 116 ms 17608 KiB
01_random_1_09.txt AC 68 ms 12524 KiB
02_random_2_00.txt AC 141 ms 22044 KiB
02_random_2_01.txt AC 138 ms 21756 KiB
02_random_2_02.txt AC 140 ms 21812 KiB
02_random_2_03.txt AC 150 ms 22260 KiB
02_random_2_04.txt AC 149 ms 22344 KiB
02_random_2_05.txt AC 148 ms 22292 KiB
02_random_2_06.txt AC 134 ms 22228 KiB
02_random_2_07.txt AC 133 ms 22176 KiB
02_random_2_08.txt AC 135 ms 22188 KiB
02_random_2_09.txt AC 168 ms 24252 KiB
02_random_2_10.txt AC 166 ms 24404 KiB
02_random_2_11.txt AC 166 ms 24304 KiB
02_random_2_12.txt AC 154 ms 23392 KiB
02_random_2_13.txt AC 154 ms 23308 KiB
02_random_2_14.txt AC 155 ms 23264 KiB
03_corner_00.txt AC 1 ms 3404 KiB
03_corner_01.txt AC 155 ms 35692 KiB
03_corner_02.txt AC 10 ms 6008 KiB


2025-08-22 (Fri)
02:34:28 +09:00