inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
x = x * 10 + ch - '0' , ch = getchar();
return x * f;
}
判断互质
C++
bool f(int x, int y) {
while (y != 0) {
if (x < y) swap(x, y);
int r = x % y;
x = y;
y = r;
}
return x == 1;
}
判断质数
C++
bool f(const int &n){
int x = sqrt(n)+1;
for(int i = 2; i < x; i++){
if(n%i == 0){
return 0;
}
}
return 1;
}
进制转换(十进制转n进制)
C++
string f(int num, int base) {
string str;
do{
int remainder = num % base;
if (remainder < 10) {
str += '0' + remainder;
} else {
str += 'A' + remainder - 10;
}
num /= base;
} while (num != 0);
reverse(str.begin(), str.end());
return str;
}
进制转换(n进制转十进制)
C++
int f(const string &str, int base) {
int n = 0;
int m = 1;
for (int i = str.length() - 1; i >= 0; --i) {
int x = 0;
if (str[i] >= '0' && str[i] <= '9') {
x = str[i] - '0';
} else {
x = str[i] - 'A' + 10;
}
n += x * m;
m *= base;
}
return n;
}