「杂题乱刷」CF1846E1 & CF1846E2

E1

链接

一眼题。

直接预处理即可。

时间复杂度 \(O(n \log_2(n))\)

代码:

点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
ll t;
ll pd[1000010];
void init()
{
	forl(i,2,1000000)
	{
		ll pw=i*i,sum=1+i+i*i;
		forl(j,2,1e18)
		{
			if(sum>1e6)
				break;
			pd[sum]=1;
			pw*=i,sum+=pw;
		}
	}
}
void solve()
{
	ll n;
	cin>>n;
	if(pd[n])
		cout<<"YES\n";
	else
		cout<<"NO\n";
}
int main()
{
	IOS;
	init();
	t=1;
	cin>>t;
	while(t--)
		solve();
    /******************/
	/*while(L<q[i].l) */
	/*    del(a[L++]);*/
	/*while(L>q[i].l) */
	/*    add(a[--L]);*/
	/*while(R<q[i].r) */
	/*	  add(a[++R]);*/
	/*while(R>q[i].r) */
	/*    del(a[R--]);*/
    /******************/
	QwQ;
}

E2

诈骗题。

发现 long long 范围内最多的幂次为 \(63\),然后二分树的分支个数即可,时间复杂度 \(O(T \times 63 \times log_2(n))\)

代码:

点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
ll t;
ll n;
ll check(ll x,ll y)
{
	__int128 ans=0,pw=1;
	forl(i,1,y+1)
	{
		ans+=pw,pw*=x;
		if(ans>n)
			return 1;
	}
	if(ans==n)
		return 2;
	return 0;
}
void solve()
{
	cin>>n;
	forl(i,2,63)
	{
		ll l=2,r=1e9;
		while(l<r)
		{
			if(check(mid,i))
				r=mid;
			else
				l=mid+1;
		}
		if(check(l,i)==2)
		{
			cout<<"YES\n";
			return ;
		}
	}
	cout<<"NO\n";
}
int main()
{
	IOS;
	t=1;
	cin>>t;
	while(t--)
		solve();
    /******************/
	/*while(L<q[i].l) */
	/*    del(a[L++]);*/
	/*while(L>q[i].l) */
	/*    add(a[--L]);*/
	/*while(R<q[i].r) */
	/*	  add(a[++R]);*/
	/*while(R>q[i].r) */
	/*    del(a[R--]);*/
    /******************/
	QwQ;
}
posted @ 2024-03-05 21:10  wangmarui  阅读(5)  评论(0编辑  收藏  举报