- zhuzixin 的博客
碎片化知识点
- @ 2026-4-11 14:13:01
//判断素数(大约是10的5次方以内)
bool prime(int x)
{
if(x < 2) return 0;
for(int i = 2; i <= x / i; i++)
if(x % i == 0)
return 0;
return 1;
}
//转任意进制的string函数写法
string to_x(int t, int x)
{
string ans = "";
while(t > 0)
{
if(t % x >= 10)
ans = char(t % x - 10 + 'a') + ans;
else
ans = char(t % x + '0') + ans;
t /= x;
}
return ans;
}