結果
| 問題 |
No.897 compαctree
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2019-10-04 21:32:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,784 bytes |
| コンパイル時間 | 2,687 ms |
| コンパイル使用メモリ | 210,944 KB |
| 最終ジャッジ日時 | 2025-01-07 20:24:29 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(long long &x){
int k;
int m=0;
x=0;
for(;;){
k = getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline int rd_int(void){
int x;
rd(x);
return x;
}
inline void wt_L(char a){
putchar_unlocked(a);
}
inline void wt_L(long long x){
int s=0;
int m=0;
char f[20];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
putchar_unlocked('-');
}
while(s--){
putchar_unlocked(f[s]+'0');
}
}
long long N;
long long K;
int main(){
int Lj4PdHRW;
long long res;
long long cur;
int KL2GvlyY = rd_int();
for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
rd(N);
rd(K);
if(K==1){
wt_L(N-1);
wt_L('\n');
continue;
}
res = 0;
N--;
cur = 1;
while(N > 0){
N -= (cur *= K);
res++;
}
wt_L(res);
wt_L('\n');
}
return 0;
}
// cLay varsion 20190929-1
// --- original code ---
// ll N, K;
// {
// ll res, cur;
// REP(rd_int()){
// rd(N,K);
// if(K==1) wt(N-1), continue;
// res = 0;
// N--;
// cur = 1;
// while(N > 0) N -= (cur *= K), res++;
// wt(res);
// }
// }
LayCurse