题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4279
题意:一个数x的f值f(x)等于小于它的正整数中不能整除x但是又与x不互质的数的个数。如果f(x)
是奇数,那么称x为real number。给定区间[a,b],问该区间有多少个real number?
分析:打表找规律。一下为1-50的答案:
3:0
4:0
5:0
6:1
7:1
8:2
9:3
10:4
11:4
12:5
13:5
14:6
15:6
16:6
17:6
18:7
19:7
20:8
21:8
22:9
23:9
24:10
25:11
26:12
27:12
28:13
29:13
30:14
31:14
32:15
33:15
34:16
35:16
36:16
37:16
38:17
39:17
40:18
41:18
42:19
43:19
44:20
45:20
46:21
47:21
48:22
49:23
50:24
Code:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define LL long long
#define pb push_back
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=100005;
LL l,r;
LL solve(LL x){
if(x<6) return 0;
LL s=(LL)floor((sqrt((double)(x))));
if(s*s>x) s--; //不加这句会WA 不明。。。T_T
return x/2-s/2+(s+1)/2-2;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
cin>>l>>r;
LL ans=solve(r)-solve(l-1);
cout<<ans<<endl;
}
return 0;
}