zoukankan      html  css  js  c++  java
  • GCD

    传送门:

    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <algorithm>
    using namespace std;
    #define ll long long
    #define re register
    const int N=1e5+10;
    const int M=1e5;
    void read(int &a)
    {
        a=0;
        int d=1;
        char ch;
        while(ch=getchar(),!isdigit(ch))
            if(ch=='-')
                d=-1;
        a=ch^48;
        while(ch=getchar(),isdigit(ch))
            a=(a<<3)+(a<<1)+(ch^48);
        a*=d;
    }
    void write(int x)
    {
        if(x<0)
            putchar(45),x=-x;
        if(x>9)
            write(x/10);
        putchar(x%10+'0');
    }
    int pri[N],cnt;
    ll mu[N];
    bool vis[N];
    inline void init()
    {
        mu[1]=1;
        for(re int i=2;i<=M;i++)
        {
            if(!vis[i])
                pri[++cnt]=i,mu[i]=-1;
            for(re int j=1;j<=cnt&&i*pri[j]<=M;j++)
            {
                vis[i*pri[j]]=1;
                if(i%pri[j]==0)
                    break;
                mu[i*pri[j]]=-mu[i];
            }
        }
        for(re int i=1;i<=M;i++)
            mu[i]+=mu[i-1];
    }
    int main()
    {
        init();
        int T,cas=0;
        read(T);
        while(T--)
        {
            cas++;
            int a,b,c,d,k;
            read(a);
            read(b);
            read(c);
            read(d);
            read(k);
            if(k==0)
            {
                printf("Case %d: 0
    ",cas);
                continue;
            }
            b/=k;
            d/=k;
            if(b>d)
                swap(b,d);
            ll ans1=0,ans2=0;
            for(re int l=1,r;l<=b;l=r+1)
            {
                r=min(b/(b/l),d/(d/l));
                ans1+=(mu[r]-mu[l-1])*(b/l)*(d/l);
            }
            for(re int l=1,r;l<=b;l=r+1)
            {
                r=b/(b/l);
                ans2+=(mu[r]-mu[l-1])*(b/l)*(b/l);
            }
            ll ans=ans1-ans2/2;
            printf("Case %d: %lld
    ",cas,ans);
        }
        return 0;
    }
  • 相关阅读:
    C语言:SQLITE3的学习
    C语言:json库使用学习
    C语言:XML学习
    glib实践篇:接口定义与实现
    glib实践篇:父类与子类
    python简易爬虫实现
    Esxi开虚拟机测试性能
    Hyper-V虚拟化性能测试
    配置飞儿云平台的PHP系统
    CentOS6.9安装OpenVZ
  • 原文地址:https://www.cnblogs.com/acm1ruoji/p/10821638.html
Copyright © 2011-2022 走看看