Submission #67153768
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
//https://drken1215.hatenablog.com/entry/2023/05/23/233000
// montgomery modint (MOD < 2^62, MOD is odd)
struct MontgomeryModInt64 {
    using mint = MontgomeryModInt64;
    using u64 = uint64_t;
    using u128 = __uint128_t;
    
    // static menber
    static u64 MOD;
    static u64 INV_MOD;  // INV_MOD * MOD ≡ 1 (mod 2^64)
    static u64 T128;  // 2^128 (mod MOD)
    
    // inner value
    u64 val;
    
    // constructor
    MontgomeryModInt64() : val(0) { }
    MontgomeryModInt64(long long v) : val(reduce((u128(v) + MOD) * T128)) { }
    u64 get() const {
        u64 res = reduce(val);
        return res >= MOD ? res - MOD : res;
    }
    
    // mod getter and setter
    static u64 get_mod() { return MOD; }
    static void set_mod(u64 mod) {
        assert(mod < (1LL << 62));
        assert((mod & 1));
        MOD = mod;
        T128 = -u128(mod) % mod;
        INV_MOD = get_inv_mod();
    }
    static u64 get_inv_mod() {
        u64 res = MOD;
        for (int i = 0; i < 5; ++i) res *= 2 - MOD * res;
        return res;
    }
    static u64 reduce(const u128 &v) {
        return (v + u128(u64(v) * u64(-INV_MOD)) * MOD) >> 64;
    }
    
    // arithmetic operators
    mint operator - () const { return mint() - mint(*this); }
    mint operator + (const mint &r) const { return mint(*this) += r; }
    mint operator - (const mint &r) const { return mint(*this) -= r; }
    mint operator * (const mint &r) const { return mint(*this) *= r; }
    mint operator / (const mint &r) const { return mint(*this) /= r; }
    mint& operator += (const mint &r) {
        if ((val += r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator -= (const mint &r) {
        if ((val += 2 * MOD - r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator *= (const mint &r) {
        val = reduce(u128(val) * r.val);
        return *this;
    }
    mint& operator /= (const mint &r) {
        *this *= r.inv();
        return *this;
    }
    mint inv() const { return pow(MOD - 2); }
    mint pow(u128 n) const {
        mint res(1), mul(*this);
        while (n > 0) {
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    // other operators
    bool operator == (const mint &r) const {
        return (val >= MOD ? val - MOD : val) == (r.val >= MOD ? r.val - MOD : r.val);
    }
    bool operator != (const mint &r) const {
        return (val >= MOD ? val - MOD : val) != (r.val >= MOD ? r.val - MOD : r.val);
    }
    friend istream& operator >> (istream &is, mint &x) {
        long long t;
        is >> t;
        x = mint(t);
        return is;
    }
    friend ostream& operator << (ostream &os, const mint &x) {
        return os << x.get();
    }
    friend mint modpow(const mint &r, long long n) {
        return r.pow(n);
    }
    friend mint modinv(const mint &r) {
        return r.inv();
    }
};
typename MontgomeryModInt64::u64
MontgomeryModInt64::MOD, MontgomeryModInt64::INV_MOD, MontgomeryModInt64::T128;
// Miller-Rabin
bool MillerRabin(long long N, vector<long long> A) {
    using mint = MontgomeryModInt64;
    mint::set_mod(N);
    
    long long s = 0, d = N - 1;
    while (d % 2 == 0) {
        ++s;
        d >>= 1;
    }
    for (auto a : A) {
        if (N <= a) return true;
        mint x = mint(a).pow(d);
        if (x != 1) {
            long long t;
            for (t = 0; t < s; ++t) {
                if (x == N - 1) break;
                x *= x;
            }
            if (t == s) return false;
        }
    }
    return true;
}
bool is_prime(long long N) {
    if (N <= 1) return false;
    else if (N == 2) return true;
    else if (N % 2 == 0) return false;
    else if (N < 4759123141LL)
        return MillerRabin(N, {2, 7, 61});
    else
        return MillerRabin(N, {2, 325, 9375, 28178, 450775, 9780504, 1795265022});
}
void YosupoPrimarityTest() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        long long A;
        cin >> A;
        if (is_prime(A))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}
//https://chiwawa-star.hatenablog.com/entry/2016/11/25/015503
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}
int main()
{
  long long l,r;
  cin >> l >> r;
  if(l==r){
    cout << 1 << endl;
    return 0;
  }
  vector<int>prime=Eratosthenes((int)1e7);
  set<int>ans;
  for(int i=0;i<prime.size();i++){
    long long cnt=prime[i];
    while(cnt<=r){
      if(l<cnt && cnt<=r)ans.insert(cnt);
      cnt*=prime[i];
    }
  }
  for(long long i=l+1;i<=r;i++)if(is_prime(i))ans.insert(i);
  cout << ans.size()+1 << endl;
}
			Submission Info
| Submission Time | |
|---|---|
| Task | E - LCM Sequence | 
| User | rotti | 
| Language | C++ 20 (gcc 12.2) | 
| Score | 500 | 
| Code Size | 5427 Byte | 
| Status | AC | 
| Exec Time | 1670 ms | 
| Memory | 36784 KiB | 
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:187:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  187 |   for(int i=0;i<prime.size();i++){
      |               ~^~~~~~~~~~~~~
			
			
				Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status | 
 | 
 | 
| 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 | 59 ms | 8524 KiB | 
| 00_sample_01.txt | AC | 1 ms | 3396 KiB | 
| 00_sample_02.txt | AC | 1670 ms | 20152 KiB | 
| 01_random_1_00.txt | AC | 1479 ms | 18720 KiB | 
| 01_random_1_01.txt | AC | 1535 ms | 19640 KiB | 
| 01_random_1_02.txt | AC | 797 ms | 13928 KiB | 
| 01_random_1_03.txt | AC | 784 ms | 13040 KiB | 
| 01_random_1_04.txt | AC | 1650 ms | 19860 KiB | 
| 01_random_1_05.txt | AC | 426 ms | 9112 KiB | 
| 01_random_1_06.txt | AC | 972 ms | 14184 KiB | 
| 01_random_1_07.txt | AC | 330 ms | 8460 KiB | 
| 01_random_1_08.txt | AC | 890 ms | 13212 KiB | 
| 01_random_1_09.txt | AC | 693 ms | 11936 KiB | 
| 02_random_2_00.txt | AC | 1571 ms | 22272 KiB | 
| 02_random_2_01.txt | AC | 1572 ms | 22292 KiB | 
| 02_random_2_02.txt | AC | 1576 ms | 22328 KiB | 
| 02_random_2_03.txt | AC | 1623 ms | 21364 KiB | 
| 02_random_2_04.txt | AC | 1630 ms | 21200 KiB | 
| 02_random_2_05.txt | AC | 1626 ms | 21200 KiB | 
| 02_random_2_06.txt | AC | 1526 ms | 23056 KiB | 
| 02_random_2_07.txt | AC | 1520 ms | 23224 KiB | 
| 02_random_2_08.txt | AC | 1525 ms | 23072 KiB | 
| 02_random_2_09.txt | AC | 1666 ms | 20396 KiB | 
| 02_random_2_10.txt | AC | 1668 ms | 20408 KiB | 
| 02_random_2_11.txt | AC | 1666 ms | 20476 KiB | 
| 02_random_2_12.txt | AC | 1639 ms | 20600 KiB | 
| 02_random_2_13.txt | AC | 1640 ms | 20748 KiB | 
| 02_random_2_14.txt | AC | 1644 ms | 20680 KiB | 
| 03_corner_00.txt | AC | 1 ms | 3556 KiB | 
| 03_corner_01.txt | AC | 1029 ms | 36784 KiB | 
| 03_corner_02.txt | AC | 114 ms | 8608 KiB |