HDU4279Number

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


2012天津online


给出a,b两个数,1<=a<=b 如果a,b不互质,且a%b != 0则说明a是b的特殊数字f[i]表示i拥有的特殊数字的个数,如果f[i]是奇数,那么i就是 real numbers

给出区间[x,y]求区间内的 real numbers的数量。


规律: real numbers为以下两类数:1.大于等于6且不为完全平方数的偶数。2.大于等于6的且为完全平方数的奇数。

“只要知道Euler-Phi函数在n>2时总是个偶数,而有奇数个因子的数一定是完全平方数就可以了。”


计数采用f(y)-f(x-1)的方法。


#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include<cstdlib>
#include <algorithm>
#include<string>
#include <time.h>
using namespace std;
const double eps=1e-7;
const int INF=(1<<30)-1;
//const double INF=1e50;
//const double pi=acos(-1);

#define maxn 101005
#define M 1000000000

int main()
{
    //freopen("a","r",stdin);
    //freopen("b","w",stdout);

    int T,kk;
    scanf("%d",&T);
    for (kk=1;kk<=T;kk++)
    {
        long long x,y;
        cin>>x>>y;

        if (x<6) x=6;
        if (y<6)
        {
            cout<<"0"<<endl;
            continue;
        }
        x--;

        long long dx,dy,d;
        dx=x/2;
        dy=y/2;
        d=dy-dx;

        long long sx,sy;
        sx=(long long)sqrt(x);
        sy=(long long)sqrt(y);

        if (sx%2==0)
        {
            if (sy%2!=0) d++;
        }
        else if (sy%2==0) d--;

        cout<<d<<endl;
    }

    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值