B. Ela's Fitness and the Luxury Number

思路:

xxxxx2=x

[x2,(x+1)2)xx2

x(x+1),x(x+2)

这里可以用一个前缀和去优化就只用考虑右边界,右边界和上面三个讨论

[x2,(x+1)x)+1

[(x+1)x,(x+2)x)+1

[(x+2)x,(x+1)2)+1

#include <bits/stdc++.h> 
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<t<<endl;

using namespace std;
const int N = 1e6 + 10;
int t;

ll get(ll x)
{
	ll res = 0, m = sqrt(x);
	res += (m - 1) * 3;
	if(x >= m * m) res ++;
	if(x >= (m + 1) * m)	res ++;
	if(x >= (m + 2) * m)	res ++;
	return res;
}

void solve()
{
	ll l, r, ans = 0; cin >> l >> r;
	
	cout << get(r) - get(l - 1) << endl;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("1.in", "r", stdin);
	cin >> t;
//	while(t --)	
//	solve();
	debug(t) 
	return 0;
}
posted @   cxy8  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示