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;
}