結果

問題 No.1666 累乗数
ユーザー inksamuraiinksamurai
提出日時 2021-09-03 23:05:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,272 ms / 2,000 ms
コード長 1,962 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 168,580 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-08-22 00:37:47
合計ジャッジ時間 23,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,544 KB
testcase_01 AC 868 ms
4,764 KB
testcase_02 AC 881 ms
4,692 KB
testcase_03 AC 887 ms
4,776 KB
testcase_04 AC 896 ms
4,568 KB
testcase_05 AC 1,271 ms
4,548 KB
testcase_06 AC 1,272 ms
4,632 KB
testcase_07 AC 1,272 ms
4,616 KB
testcase_08 AC 1,264 ms
4,564 KB
testcase_09 AC 992 ms
4,684 KB
testcase_10 AC 1,002 ms
4,632 KB
testcase_11 AC 1,010 ms
4,624 KB
testcase_12 AC 1,013 ms
4,688 KB
testcase_13 AC 1,231 ms
4,564 KB
testcase_14 AC 1,234 ms
4,632 KB
testcase_15 AC 1,248 ms
4,640 KB
testcase_16 AC 1,243 ms
4,556 KB
testcase_17 AC 1,100 ms
4,684 KB
testcase_18 AC 1,124 ms
4,560 KB
testcase_19 AC 1,117 ms
4,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end());
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define vec(...) vector<__VA_ARGS__>
#define _3sSOzgI ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;
using pii=pair<int,int>;
using vi=vec(int);
const int mxn=12000;
vi rabbits={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
const int m=sz(rabbits);
ll prod[1048576];
vi cand;

void slv(){
	int n;
	cin>>n;
	auto findmagic=[&](ll g,ll x){
		ll l=1,r=x,c=-1;
		if(g>=60){
			return c=1;
		}
		while(l<=r){
			ll m=(l+r)/2;
			ll jj=g;
			ll y=1;
			bool pok=1;
			while(jj>0){
				if(y>x/m){
					pok=0;
					break;
				}
				y*=m;
				jj=jj-1;
			}
			if(pok){
				c=m;
				l=m+1;
			}else{
				r=m-1;
			}
		}
		return c;
	};
	auto f=[&](ll x){
		ll sum=0;
		for(auto msk : cand){
			ll g=1;
			bool caughtone=0;
			g=prod[msk];
			int k=__builtin_popcount(msk);
			ll up;
			if(g<60) up=findmagic(g,x);
			else up=1;
			if(k%2) sum+=up;
			else sum-=up;
		}
		sum+=2380;
		// printf("%lld\n",sum);
		return sum;
	};
	// f(10);2
	ll l=0,r=997995681331086344,c=-1;
	while(l<=r){
		ll m=(l+r)/2;
		if(f(m)>=n){
			r=m-1;
		}else{
			c=m;
			l=m+1;
		}
	}
	printf("%lld\n",c+1);
	// cout<<c+1<<"\n";
}

int main(){
_3sSOzgI;
	int sum=0;
	crep(msk,1,(1<<m)){
		int k=__builtin_popcount(msk);
		if(k>4){
			if(k%2) sum+=1;
			else sum-=1;
		}else{
			prod[msk]=1;
			rep(i,m){
				if(msk&(1<<i)){
					prod[msk]*=rabbits[i];
				}
			}
			cand.pb(msk);
		}
	}
	// cout<<sum<<"\n";
	// slv();
	// cout<<sum<<"\n";
	int t;
	cin>>t;
	rep(cs,t){
		slv();
	}
//	
	return 0;
}
0