其他分享
首页 > 其他分享> > D - Together Square

D - Together Square

作者:互联网

D - Together Square

https://atcoder.jp/contests/abc254/tasks/abc254_d

 

 

思路

 

Code

#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
int main(){
    long long n;
    cin>>n;
    long long sq[1000],cnt=0;
    for(int i=1;i*i<=n;i++){
        sq[i]=i*i;
        cnt=i;
    }
    long long ans=n;
    for(int i=1;i<=cnt;i++){
        for(int j=i+1;j<=cnt;j++){
            if(gcd(i,j)==1){
                ans+=(n/sq[j])*2;
            }
//            cout<<sq[j]<<endl;
        }
    }
    cout<<ans<<endl;
}

 

数学证明

https://www.cnblogs.com/tsrigo/p/16344714.html

 

标签:Square,return,gcd,int,long,Together,https,abc254
来源: https://www.cnblogs.com/lightsong/p/16355247.html