#include <iostream>
#include <cassert>
#include <array>
#include <set>
using namespace std;
void checkB(long long a, long long b, set<array<int, 3> >& result) {
// cerr << a << ":" << endl;
// sprawdza, na ile sposobów b da się zapisać
// jako 1 + x(1+y), x > 1, y > 1
long long sum = 0;
for (long long x = 2; 1 + (x * (1 + x)) <= b; x++) {
// b == 1 + x(1+y)
// b - 1 == x(1+y)
// 1+y == (b-1)/x
// y == ((b-1)/x) - 1
if ((b - 1) % x == 0) {
long long y = (b - 1) / x - 1;
if (y > 1) {
sum++;
long long B = a * x;
long long C = B * y;
// cerr << a << " " << B << " " << C << endl;
array<int, 3> arr = {a, B, C};
result.insert(arr);
// assert( B % a == 0);
// assert( C % B == 0);
// assert( C % a == 0);
// assert( a + B + C == a * b);
}
}
// swap(x,y)
// b == 1 + x(1+y)
// x(1+y) = b - 1
// x = (b-1)/(1+y)
if ((b - 1) % (1 + x) == 0) {
long long y = (b - 1) / (x + 1);
if (y > 1) {
sum++;
long long B = a * y;
long long C = B * x;
// cerr << a << " " << B << " " << C << endl;
array<int, 3> arr = {a, B, C};
result.insert(arr);
// assert( B % a == 0);
// assert( C % B == 0);
// assert( C % a == 0);
// assert( a + B + C == a * b);
}
}
}
}
int main() {
long long n;
cin >> n;
// Sumujemy na ile sposobów n da się to zapisać
// jako a(1+x(1+y)), x > 1, y > 1, a >= 1
set<array<int, 3> > result;
for (long long a = 1; a * a <= n; a++) {
if (n % a == 0) {
// maksymalnie O(log(n)) dzielników
checkB(a, n / a, result);
checkB(n / a, a, result);
}
}
cout << result.size() << endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <iostream> #include <cassert> #include <array> #include <set> using namespace std; void checkB(long long a, long long b, set<array<int, 3> >& result) { // cerr << a << ":" << endl; // sprawdza, na ile sposobów b da się zapisać // jako 1 + x(1+y), x > 1, y > 1 long long sum = 0; for (long long x = 2; 1 + (x * (1 + x)) <= b; x++) { // b == 1 + x(1+y) // b - 1 == x(1+y) // 1+y == (b-1)/x // y == ((b-1)/x) - 1 if ((b - 1) % x == 0) { long long y = (b - 1) / x - 1; if (y > 1) { sum++; long long B = a * x; long long C = B * y; // cerr << a << " " << B << " " << C << endl; array<int, 3> arr = {a, B, C}; result.insert(arr); // assert( B % a == 0); // assert( C % B == 0); // assert( C % a == 0); // assert( a + B + C == a * b); } } // swap(x,y) // b == 1 + x(1+y) // x(1+y) = b - 1 // x = (b-1)/(1+y) if ((b - 1) % (1 + x) == 0) { long long y = (b - 1) / (x + 1); if (y > 1) { sum++; long long B = a * y; long long C = B * x; // cerr << a << " " << B << " " << C << endl; array<int, 3> arr = {a, B, C}; result.insert(arr); // assert( B % a == 0); // assert( C % B == 0); // assert( C % a == 0); // assert( a + B + C == a * b); } } } } int main() { long long n; cin >> n; // Sumujemy na ile sposobów n da się to zapisać // jako a(1+x(1+y)), x > 1, y > 1, a >= 1 set<array<int, 3> > result; for (long long a = 1; a * a <= n; a++) { if (n % a == 0) { // maksymalnie O(log(n)) dzielników checkB(a, n / a, result); checkB(n / a, a, result); } } cout << result.size() << endl; return 0; } |
English