//KZNS
#include <cstdio>
using namespace std;
inline int F(int n, int a, int b, int x) {
return (a*x+b)%n;
}
int main() {
freopen("functiona.in", "r", stdin);
freopen("functiona.out", "w", stdout);
int n;
int Q = 0;
bool f;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
for (int k = 0; k < i; k++) {
f = true;
for (int ii = 0; ii < n; ii++) {
if (F(i, j, k, F(i, j, k, ii)) != F(i, j, k, ii)) {
f = false;
break;
}
}
if (f) {
Q++;
}
}
}
}
printf("%d\n", Q);
return 0;
}
//UBWH