Logo aaa 的博客

博客

AT5308题解

...
aaa
2025-12-01 12:54:07

本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2021-03-25 14:56:51

思路

$n$ 只要不为 $0$ 就不停循环,$++ans$ 并让 $n/=k$。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main(){
	int ans=0;
	for(int n=read(),k=read();n;n\/=k,++ans);\/\/压行
	cout<<ans;
	return 0;
}

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。