← Back to List

18825번: 눈치게임 A+B! A-B! A+B! 터렛! A+B! 피보나치 함수! A+B! A-B! A+B! 어린 왕자! A+B! ACM Craft! A+B! A-B! A+B! 습격자 초라기! A+B! 벡터 매칭! A+B! A-B! A+B! A/B! A+B! 터렛! A+B! A-B! A+B! 분산처리! A+B! A+B! 마셔라! 마셔라 마셔라! 마셔라 틀이 들어간다! ↗

Solutions

C++14
843 B | 843 chars
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

ll mo[1100000];
ll m,M;

void mobius(ll Max) {
    for(ll x = 1; x<=Max; x++) {
        mo[x] = 1;
    }
    for(ll x=2; x<=Max; x++) {
        if(mo[x] == 1) {
            for(ll y=x; y<=Max; y+=x) {
                mo[y] *= -x;
            }
            for(ll y=x*x; y<=Max; y+=x*x) {
                mo[y] = 0;
            }
        }
    }
    for(ll x=2; x<=Max; x++) {
        if(mo[x] == x) mo[x] =1;
        else if(mo[x] == -x) mo[x] = -1;
        else if(mo[x] <0) mo[x] =1;
        else if(mo[x] >0) mo[x] =-1;
    }
}

ll free_count(ll K) {
    ll ret = 0;
    for(ll x = 1; x*x<=K; x++) {
        ret += mo[x]*(K/(x*x));
    }
    return ret;
}

int main() {

    cin >> m >> M;

    mobius(1000000);
    cout<<free_count(M) - free_count(m-1);

}