C - 2^a b^2

题目链接:https://atcoder.jp/contests/abc400/tasks/abc400_c

题意:

定义一个数当其为2^a * b^2为好数
其中a,b>=1
求[1,n]好数的个数(n<=1e18)

思路:

从1~63枚举2的幂次
由于b为偶数时会在下一个幂次再次出现,所以对于每个幂次我们只需要统计奇数个数即可
注意(1<<i)和(1ll<<i)是不同的前者最多移动31位,再多就变为负数
后者可以移动63位
sqrtl比sqrt精度更高,当数字过大时用sqrtl

void solve(){
	int n;cin>>n;
	int cnt=0;
	for(int i=1;i<=63;i++){
		if((1ll<<i)>n)break;
		int k=(1ll<<i);
		int temp=n/k;
		int p=sqrtl(temp);
		cnt+=(p+1)/2;
	}
	cout<<cnt<<endl;
}
posted @ 2025-04-07 17:12  Marinaco  阅读(21)  评论(0)    收藏  举报
//雪花飘落效果