判素数
bool isprime(int n)
{
if (n < 2) return 0;
int t = sqrt(n);
for (int i = 2; i <= t; i++)
if (n % i == 0) return 0;
return 1;
}
约数和
int ysh(int n)
{
int s = 0;
int t = sqrt(n);
for (int i = 1; i <= t; i++)
if (n % i == 0) s += i + n / i;
if (t * t == n) s -= t;
return s;
}
质因子之和
int zyzzh(int n)
{
int s = 0;
int t = sqrt(n);
for (int i = 2; i <= t; i++)
{
while (n % i == 0)
{
s += i;
n /= i;
}
if (n == 1) break;
}
if (n != 1) s += n;
return s;
}
倒序数
int dxs(int n)
{
i nt dao = 0;
while (n)
{
dao = dao * 10 + n % 10;
n /= 10;
}
return dao;
}
数字和
int szh(int n)
{
int s = 0;
while (n)
{
s += n % 10;
n /= 10;
}
return s;
}
最大公约数
int gcd(int m, int n)
{
while (m != 0)
{
int k = m % n;
m = n;
n = k;
}
return m;
}