HDU 4279 Number(数学题,找规律)
2015-02-18 12:17
537 查看
题目大意:
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;
}
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;
}
相关文章推荐
- HDU 4279 Number 规律题
- HDU 4279 Number(找规律)
- HDU 4279 Number-------找规律题
- HDU 4279 Number(找规律)
- HDU 4279 Number(找规律)
- HDU 4279 Number [数学?]
- HDU 4279 Number (数论,数学)
- hdu 4279 Number(找规律)
- HDU 4279 Number (打表找规律)
- HDU 4279(数学+找规律)
- hdu 4279 Number
- HDU 3573 Buy Sticks(数学规律)
- HDU-4279 Number 欧拉函数,因子分解综合
- hdu 4279 Number
- Hdu 4279 - Number
- 数学题(找规律)-hdu-4371-Minimum palindrome
- HDU 4608 I-number (数学&字符串处理)
- hdu 4279(规律题)
- HDU 4279 - Number
- hdu 4279 Number