(UVa) 10990 – Another New Function

0

/****************************************************************
   ▄█    █▄       ▄████████    ▄████████  ▄█  ▀█████████▄
  ███    ███     ███    ███   ███    ███ ███    ███    ███
  ███    ███     ███    ███   ███    █▀  ███   ███    ███
 ▄███▄▄▄▄███▄▄   ███    ███   ███        ███  ▄███▄▄▄██▀
▀▀███▀▀▀▀███▀  ▀███████████ ▀███████████ ███ ▀▀███▀▀▀██▄
  ███    ███     ███    ███          ███ ███    ███    ██▄
  ███    ███     ███    ███    ▄█    ███ ███    ███    ███
  ███    █▀      ███    █▀   ▄████████▀  █▀   ▄█████████▀
****************************************************************/



#include<bits/stdc++.h>


#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) FOR(i, 0, n)
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define ll long long
#define dd double
#define all(v) v.begin(), v.end()
#define PI acos(-1.0)
#define mem(ara, value) memset(ara, value, sizeof(ara))
#define paii pair<int, int>
#define pall pair<ll, ll>
#define SZ(a) int(a.size())
#define read(nm) freopen(nm, "r", stdin)
#define write(nm) freopen(nm, "w", stdout)

#define take(args...) asdf,args
#define dump(x) cerr<<#x<<" = "<<x<<endl
#define debug(args...) cerr,args; cerr<<endl;
using namespace std;


template<typename T>
ostream& operator<<(ostream& output, vector<T>&v)
{
    output<<"[ ";
    if(SZ(v))
    {
        output<<v[0];
    }
    FOR(i, 1, SZ(v))
    {
        output<<", "<<v[i];
    }
    output<<" ]";
    return output;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& output, pair<T1, T2>&p)
{
    output<<"( "<<p.fr<<", "<<p.sc<<" )";
    return output;
}




template<typename T>
ostream& operator,(ostream& output, T x)
{
    output<<x<<" ";
    return output;
}



struct ASDF{
    ASDF& operator,(int &a) {
        sf("%d", &a);
        return *this;
    }
    ASDF& operator,(long int &a){
        sf("%ld", &a);
        return *this;
    }
    ASDF& operator,(long long int &a){
        sf("%lld", &a);
        return *this;
    }
    ASDF& operator,(char &c){
        sf("%c", &c);
        return *this;
    }
    ASDF& operator,(double &d){
        sf("%lf", &d);
        return *this;
    }

    template<typename T>
    ASDF& operator,(T &a){
        cin>>a;
        return *this;
    }
}asdf;



//Header ends here

#define MAXX 2000007



int phi[MAXX];

ll depth[MAXX], comu[MAXX];


void generatePhi()
{
    loop(i, MAXX)
    {
        phi[i] = i;
    }

    for(int i=2; i<MAXX; i+=2)
    {
        phi[i] /= 2;
    }

    bool isPrime[MAXX];

    mem(isPrime, 1);

    for(int i=3; i<MAXX; i+=2)
    {
        if(isPrime[i])
        {
            for(int j=i; j<MAXX; j+=i)
            {
                phi[j] = (phi[j]/i) * (i-1);
                isPrime[j] = false;
            }
        }
    }
}

void generateDepth()
{
    for(int i=2; i<MAXX; i++)
    {
        depth[i] = depth[ phi[i] ] + 1;
    }
}


void generateComu()
{
    for(int i=1; i<MAXX; i++)
    {
        comu[i] = comu[i-1] + depth[i];
    }
}






void init()
{
    generatePhi();

    generateDepth();

    generateComu();
}


int main()
{
    init();


    int kases, n, m;

    take(kases);

    while(kases--)
    {
        take(m, n);

        pf("%lld\n", comu[n] - comu[m-1]);
    }



    return 0;
}