HDU 2588 GCD

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2588

题意:

问你有多少个x满足

gcd(x,n)>=m&&1<=x<=n

题解:

欧拉函数

\[我们假设gcd(x,n)=s;s>=m\\ 我们现在要求的就是s的个数\\ 设x=s*a,n=s*b\\ 因为gcd(x,n)=s,所以gcd(a,b)=1\\ 反证:如果gcd(a,b)!=1,那么gcd(x,n)=t>s \\ 因为x<=n所以 a<=b 求a<=b,gcd(a,b)的个数就是欧拉函数\\ 所以我们枚举s,根据约数定理我们可以知道如果n\%s==0,那么n\%(n/s)==0\\ 这样我们就可以在 O(\sqrt{n})内枚举出所有s\\ \]

/**
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */
// warm heart, wagging tail,and a smile just for you!
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \\  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"

const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
LL phi (LL n) {
    int res = n;
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            res -= res / i;
            while (n % i == 0) n /= i;
        }
    }
    return n > 1 ? res / n * (n - 1) : res;
}
int main() {
#ifndef ONLINE_JUDGE
    FIN
#endif
    LL n, m;
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%lld%lld", &n, &m);
        LL ans = 0;
        for(int s = 1; s * s <= n; s++) {
            if(n % s == 0) {
                if(s >= m) ans += phi(n / s);//b=n/s
                if(s * s != n && n / s >= m) {
                    ans += phi(b);//b1=n/b=n/(n/s)=s
                }
            }
        }
        printf("%lld\n", ans);
    }

    return 0;
}
posted @ 2019-05-22 21:35  buerdepepeqi  阅读(144)  评论(0编辑  收藏  举报