cf 1062d 思维 欧拉筛变形

http://codeforces.com/contest/1062/problem/D

题意:给个n ,在n之内 所有(a,b) ,如果存在唯一的x 使a*|x| == b 或者 b* |x| == a   (a,b>2)那么ans + |x| 求最后结果

思路:如果a%b==0那么肯定是唯一的x了,枚举(a,b)加上他们的商就好了

   枚举的(a,b)的时候 ,用欧拉筛的思想,第二重用a的倍数来枚举...

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

const int N = 1e4+4;
const int INF = 1E9+4;
const ll mod = 1e9+7;

int n,m;
int a[N],b[N];
vector<int>p;
vector<int>V[1000004];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    ll ans = 0;
    for(int i=2;i<=n;++i){
        for(int j = i+i;j<=n;j+=i){
            ans += j/i;
        }
    }
    cout<<ans*4<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/wjhstudy/p/9986106.html