萌新妹子30分求助
查看原帖
萌新妹子30分求助
404469
LJN1117楼主2023/9/24 00:25

RT,悬赏2关

My Code

#include<bits/stdc++.h>
#define int long long

using namespace std;

int t;

inline int read(){
  int s=0,w=1;
  char ch=getchar();
  while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
  while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
  return s*w;
}

signed main(){
// 	ios::sync_with_stdio(false);
// 	cin.tie(0);cout.tie(0);
   t=read();
   while(t--){
   	int n,k,s=1,ans=0;
   	n=read();k=read();
   	if(k==1){
   	    cout<<"0\n";
   	    continue;
   	}
   	while(n>0){
   		ans+=n*s;
   		s*=-1;
   		n/=k;
   	}
   	cout<<ans<<endl;
   }
   return 0;
}
2023/9/24 00:25
加载中...