結果

問題 No.897 compαctree
ユーザー 沙耶花
提出日時 2019-10-04 21:30:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 166,320 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-03 07:15:01
合計ジャッジ時間 2,141 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000

//aのb乗
long long beki(long long a,long long b){
	long long x = 1;
	while(b!=0){
		if(b&1){
			x*=a;
		}
		a*=a;
		b>>=1;
	}
	return x;
}

int main(){
	/*
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}*/
	
	int Q;
	cin>>Q;
	for(int i=0;i<Q;i++){
		int N,K;
		cin>>N>>K;
		
		int ans = 0;
		if(K==1)ans=N-1;
		else{
			N--;
			long long a = 0;
			for(int j=0;true;j++){
				a += beki(K,j);
				if(a>N){
					ans = j;
					break;
				}
			}
			if(N==0)ans=0;
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}

0