结论:
完
全
平
方
数
的
因
子
数
为
奇
数
完全平方数的因子数为奇数
完 全 平 方 数 的 因 子 数 为 奇 数
解题思路:一个灯是否开着与它的因子个数有关系,如果它的因子个数为奇数,则关闭。完全平方数的因子数是奇数的,但是题目说了1的倍数不算,那么去掉1这个因子,完全平方数的因子数为偶数,只需要把L ~ R区间的因子个数减去L ~ R区间的完全平方数即可。一个区间的完全平方数为
s
q
r
t
(
R
)
−
s
q
r
t
(
L
)
sqrt(R)-sqrt(L)
s q r t ( R ) − s q r t ( L ) 。
PS:要强转格式
#include <bits/stdc++.h>
#define x first
#define y second
#define mem(h) memset(h,-1,sizeof h)
#define mcp(a,b) memcpy(a,b,sizeof b)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair< int , int > PII;
typedef pair< double , double > PDD;
namespace IO{
inline LL read ( ) {
LL o= 0 , f= 1 ; char c= getchar ( ) ;
while ( c< '0' || c> '9' ) { if ( c== '-' ) f= - 1 ; c= getchar ( ) ; }
while ( c>= '0' && c<= '9' ) { o= o* 10 + c- '0' ; c= getchar ( ) ; }
return o* f;
}
} using namespace IO;
const int N= 1e3 + 7 , M= 2e5 + 7 , INF= 0x3f3f3f3f , mod= 1e8 + 7 , P= 131 ;
LL n, L, R;
int main ( ) {
cin>> n>> L>> R;
LL sum= R- L+ 1 ;
LL sq_num= ( LL) sqrt ( R) - ( LL) sqrt ( L) ;
cout<< sum- sq_num<< endl;
return 0 ;
}