hdu 4279 Number(找规律)

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4279

解题思路:

题目大意:

定义f(x)是大于0小于x中不能被x整除且与x不互质的数的个数,如果f[x]是奇数,那么x就是 real numbers。

给你两个数x与y ,求出在他们之间的real number数的个数。

找规律,打表即可。。。

打表代码:

#include <iostream>
#include <cstdio>
using namespace std;

int gcd(int a,int b){
    if(b == 0)
        return a;
    return gcd(b,a%b);
}

int main(){
    int tmp = 1000;
    for(int i = 1; i <= tmp; i++){
        int num = 0;
        for(int j = 1; j < i-1; j++){
            int m = gcd(i,j);
            if(m != j && m>1)
                num++;
        }
        if(num%2)
            printf("%d\n",i);
    }
    return 0;
}


AC代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long double ld;
typedef long long ll;

ll solve(ll x){
    if(x < 6)
        return 0;
    ll xx = (ll)sqrt((ld)x);
    //这题卡精度卡的比较紧,ll xx = (ll)sqrt(x*1.0);这样写并不能过
    //转化为long double才能过。。。
    if(xx%2)
        return x/2-1;
    else
        return x/2-2;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        ll x,y;
        scanf("%lld%lld",&x,&y);
        printf("%lld\n",solve(y)-solve(x-1));
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值