Submission #3438868


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

vector<int> divisor(int n){
    vector<int> ret;
    for(int i=1; i*i<=n; ++i){
        if(n%i == 0){
            ret.pb(i);
            if(i != n/i) ret.pb(n/i);
        }
    }
    // sort(all(ret));
    return ret;
}

const int N = 1000002;
// int idx[N];
ll ct[N];
vector<int> divs[N];

int main(){

    int n,k;
    scanf(" %d %d", &n, &k);

    vector<int> a(n);
    rep(i,n) scanf(" %d", &a[i]);
    sort(all(a));

    // vector<int> dk = divisor(k);
    // int D = dk.size();

    vector<int> da;
    rep(i,n){
        if( !(i>0 && a[i-1] == a[i]) ) da = divisor(a[i]);
        for(int j:da) divs[j].pb(i);
    }

    // rep(i,D){
    //     printf(" %d (%d) : ",i,dk[i]);
    //     dbg(divs[i]);
    // }

    rep(i,N){
        const vector<int> &div = divs[i];
        int sz = div.size();
        if(sz <= 1) continue;

        // printf(" %d :",i);
        // dbg(div);

        int r = sz-1;
        rep(l,sz){
            int lidx = div[l];
            while(r>=0){
                int ridx = div[r];
                if(a[lidx] + a[ridx] >= k) --r;
                else break;
            }

            int num = sz-1 - max(l,r);
            // printf(" %d %d  %d\n",i,l,num);
            ct[i] += num;
        }
    }

    ll ans = 0;
    for(int i=N-1; i>0; --i){
        // dbg(i);
        for(int j=i*2; j<N; j+=i){
            ct[i] -= ct[j];
        }

        if(k%i == 0) ans += ct[i];
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task I - Buffalo
User SyntaxSato
Language C++14 (GCC 5.4.1)
Score 800
Code Size 2034 Byte
Status AC
Exec Time 1607 ms
Memory 341684 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %d %d", &n, &k);
                            ^
./Main.cpp:36:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     rep(i,n) scanf(" %d", &a[i]);
                                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 78
Set Name Test Cases
Sample 01_sample_01, 01_sample_02, 01_sample_03
All 01_sample_01, 01_sample_02, 01_sample_03, 02_handmake_01, 02_handmake_02, 02_handmake_03, 02_handmake_04, 02_handmake_05, 02_handmake_06, 02_handmake_07, 02_handmake_08, 02_handmake_09, 02_handmake_10, 02_handmake_11, 02_handmake_12, 02_handmake_13, 02_handmake_14, 03_two_rand_01, 03_two_rand_02, 03_two_rand_03, 03_two_rand_04, 03_two_rand_05, 03_two_rand_06, 03_two_rand_07, 03_two_rand_08, 03_two_rand_09, 03_two_rand_10, 04_small_rand_01, 04_small_rand_02, 04_small_rand_03, 04_small_rand_04, 04_small_rand_05, 05_large_rand_01, 05_large_rand_02, 05_large_rand_03, 05_large_rand_04, 05_large_rand_05, 05_large_rand_06, 05_large_rand_07, 05_large_rand_08, 05_large_rand_09, 05_large_rand_10, 06_large_No_01, 06_large_No_02, 06_large_No_03, 06_large_No_04, 06_large_No_05, 07_large_Yes_01, 07_large_Yes_02, 07_large_Yes_03, 07_large_Yes_04, 07_large_Yes_05, 07_large_Yes_06, 07_large_Yes_07, 07_large_Yes_08, 07_large_Yes_09, 07_large_Yes_10, 08_corner_01, 08_corner_02, 08_corner_03, 08_corner_04, 08_corner_05, 09_large_rand_No_01, 09_large_rand_No_02, 09_large_rand_No_03, 10_highly_composite_01, 10_highly_composite_02, 10_highly_composite_03, 11_highly_composite_K_01, 11_highly_composite_K_02, 11_highly_composite_K_03, 11_highly_composite_K_04, 11_highly_composite_K_05, 12_prime_K_01, 12_prime_K_02, 12_prime_K_03, 12_prime_K_04, 12_prime_K_05
Case Name Status Exec Time Memory
01_sample_01 AC 38 ms 28928 KiB
01_sample_02 AC 38 ms 28928 KiB
01_sample_03 AC 37 ms 28928 KiB
02_handmake_01 AC 37 ms 28928 KiB
02_handmake_02 AC 37 ms 28928 KiB
02_handmake_03 AC 37 ms 28928 KiB
02_handmake_04 AC 37 ms 28928 KiB
02_handmake_05 AC 37 ms 28928 KiB
02_handmake_06 AC 37 ms 28928 KiB
02_handmake_07 AC 37 ms 28928 KiB
02_handmake_08 AC 37 ms 28928 KiB
02_handmake_09 AC 42 ms 28928 KiB
02_handmake_10 AC 38 ms 28928 KiB
02_handmake_11 AC 37 ms 28928 KiB
02_handmake_12 AC 38 ms 28928 KiB
02_handmake_13 AC 37 ms 28928 KiB
02_handmake_14 AC 38 ms 28928 KiB
03_two_rand_01 AC 37 ms 28928 KiB
03_two_rand_02 AC 37 ms 28928 KiB
03_two_rand_03 AC 37 ms 28928 KiB
03_two_rand_04 AC 37 ms 28928 KiB
03_two_rand_05 AC 37 ms 28928 KiB
03_two_rand_06 AC 38 ms 28928 KiB
03_two_rand_07 AC 37 ms 28928 KiB
03_two_rand_08 AC 37 ms 28928 KiB
03_two_rand_09 AC 37 ms 28928 KiB
03_two_rand_10 AC 37 ms 28928 KiB
04_small_rand_01 AC 40 ms 29184 KiB
04_small_rand_02 AC 40 ms 29056 KiB
04_small_rand_03 AC 38 ms 29056 KiB
04_small_rand_04 AC 37 ms 28928 KiB
04_small_rand_05 AC 39 ms 29056 KiB
05_large_rand_01 AC 822 ms 60532 KiB
05_large_rand_02 AC 690 ms 55408 KiB
05_large_rand_03 AC 283 ms 41852 KiB
05_large_rand_04 AC 536 ms 50292 KiB
05_large_rand_05 AC 256 ms 40576 KiB
05_large_rand_06 AC 507 ms 49396 KiB
05_large_rand_07 AC 205 ms 38784 KiB
05_large_rand_08 AC 294 ms 42232 KiB
05_large_rand_09 AC 221 ms 39420 KiB
05_large_rand_10 AC 847 ms 60524 KiB
06_large_No_01 AC 934 ms 73432 KiB
06_large_No_02 AC 937 ms 73180 KiB
06_large_No_03 AC 864 ms 74080 KiB
06_large_No_04 AC 632 ms 70736 KiB
06_large_No_05 AC 180 ms 60364 KiB
07_large_Yes_01 AC 785 ms 86976 KiB
07_large_Yes_02 AC 825 ms 86852 KiB
07_large_Yes_03 AC 630 ms 85812 KiB
07_large_Yes_04 AC 540 ms 88108 KiB
07_large_Yes_05 AC 119 ms 58436 KiB
07_large_Yes_06 AC 476 ms 110052 KiB
07_large_Yes_07 AC 473 ms 109924 KiB
07_large_Yes_08 AC 418 ms 149420 KiB
07_large_Yes_09 AC 251 ms 107096 KiB
07_large_Yes_10 AC 519 ms 110468 KiB
08_corner_01 AC 682 ms 84024 KiB
08_corner_02 AC 673 ms 84024 KiB
08_corner_03 AC 722 ms 88904 KiB
08_corner_04 AC 654 ms 84552 KiB
08_corner_05 AC 223 ms 81080 KiB
09_large_rand_No_01 AC 517 ms 50796 KiB
09_large_rand_No_02 AC 155 ms 34940 KiB
09_large_rand_No_03 AC 615 ms 55276 KiB
10_highly_composite_01 AC 1607 ms 320876 KiB
10_highly_composite_02 AC 1446 ms 341684 KiB
10_highly_composite_03 AC 1373 ms 313396 KiB
11_highly_composite_K_01 AC 926 ms 64100 KiB
11_highly_composite_K_02 AC 932 ms 64104 KiB
11_highly_composite_K_03 AC 945 ms 63980 KiB
11_highly_composite_K_04 AC 954 ms 64100 KiB
11_highly_composite_K_05 AC 956 ms 64104 KiB
12_prime_K_01 AC 935 ms 64104 KiB
12_prime_K_02 AC 946 ms 64112 KiB
12_prime_K_03 AC 970 ms 64104 KiB
12_prime_K_04 AC 961 ms 63972 KiB
12_prime_K_05 AC 926 ms 64112 KiB