bzoj 2005

基本就是推式子,见博客https://blog.csdn.net/lleozhang/article/details/83416791

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#define ll long long
#define maxn 1000000
using namespace std;
int phi[1000005];
int pri[1000005];
bool used[1000005];
int n,m;
int tot=0;
void init()
{
    phi[1]=1;
    for(int i=2;i<=maxn;i++)
    {
        if(!used[i])
        {
            pri[++tot]=i;
            phi[i]=i-1;
        }
        for(int j=1;j<=tot&&i*pri[j]<=maxn;j++)
        {
            used[i*pri[j]]=1;
            if(i%pri[j]==0)
            {
                phi[i*pri[j]]=phi[i]*pri[j];
                break;
            }else
            {
                phi[i*pri[j]]=phi[i]*(pri[j]-1);
            }
        }
    }
}
int main()
{
    init();
    scanf("%d%d",&n,&m);
    ll ans=0;
    for(int i=1;i<=min(n,m);i++)
    {
        ans+=(ll)phi[i]*(ll)(n/i)*(ll)(m/i);
    }
    ans*=2ll;
    ans-=(ll)n*(ll)m;
    printf("%lld\n",ans);
    return 0;
}

 

posted @ 2018-10-26 16:25  lleozhang  Views(...)  Comments(...Edit  收藏
levels of contents