Stay Hungry,Stay Foolish!

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


 

posted @ 2022-06-08 12:44  lightsong  阅读(47)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel