HDU 4279 Number(数学题,找规律)

题目大意:

Here are two numbers A and B (0 < A <= B). If B cannot be divisible by A, and A and B are not co-prime numbers, we define A as a special number of B.
  For each x, f(x) equals to the amount of x’s special numbers.
  For example, f(6)=1, because 6 only have one special number which is 4. And f(12)=3, its special numbers are 8,9,10.
  When f(x) is odd, we consider x as a real number.
  Now given 2 integers x and y, your job is to calculate how many real numbers are between them.

解题思路:

所有的real number即是大于4的不是偶数平方的偶数或者奇数平方的奇数。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define LL long long 
using namespace std;
LL solve(LL n)
{
	if(n <= 4) return 0;
	LL res = (n - 4) / 2;
	LL t = sqrt(n);
	if(t & 1) res ++;
	return res;
}
int main()
{
	LL l, r;
	int T;
	scanf("%d", &T);
	while(T--)
	{
		cin>>l>>r;
		cout<< solve(r) - solve(l-1)<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值