ABC243G Sqrt
Posted solemntee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABC243G Sqrt相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
unsigned ll a[100005];
unsigned ll Sqrt(unsigned ll x)
unsigned ll l=1,r=5e9;
while(l<r)
unsigned ll mid=(l+r+1)>>1;
if(mid*mid<=x)l=mid;
else r=mid-1;
return l;
int main()
a[1]=1;
for(int i=2;i<=100000;i++)a[i]=a[i-1]+a[Sqrt(i)];
struct edge
unsigned ll l,r;
unsigned ll val;
;
vector<edge>v;
for(int i=1;i<=100000;i++)v.push_back(1LL*i*i,1LL*(i+1)*(i+1)-1,a[i]);
int t;
scanf("%d",&t);
while(t--)
unsigned ll x;
cin>>x;
if(Sqrt(x)<=100000)cout<<a[Sqrt(x)]<<endl;
else
unsigned ll ans=a[100000];
unsigned ll mark=Sqrt(x);
unsigned ll L=1e5+1,R=mark;
auto f=[&](unsigned ll l,unsigned ll r,unsigned ll L,unsigned ll R)->unsigned ll
if(r<L||l>R)return 0;
if(L>=l&&r>=R)return R-L+1;
if(l>=L&&R>=r)return r-l+1;
if(L>=l&&r>=L&&R>=r)return r-L+1;
if(l>=L&&R>=l&&r>=R)return R-l+1;
;
for(auto [l,r,val]:v)
ans+=val*f(l,r,L,R);
cout<<ans<<endl;
return 0;
以上是关于ABC243G Sqrt的主要内容,如果未能解决你的问题,请参考以下文章