Cube Problem

Yaroslav, Andrey and Roman love playing cubes. Sometimes they get together and play cubes for hours and hours!

Today they got together again and they are playing cubes. Yaroslav took unit cubes and composed them into an a × a × a cube, Andrey made a b × b × b cube and Roman made a c × c × c cube. After that the game was finished and the guys left. But later, Vitaly entered the room. He saw the cubes and wanted to make a cube as well. But what size should the cube be? Of course it should be a large cube with the side of length a + b + c. Besides, Vitaly decided to decompose the cubes built by Yaroslav, Andrey and Roman and compose his own large cube out of them. However, it turned out that the unit cubes he got from destroying the three cubes just weren’t enough to make a large cube. We know that Vitaly was short of exactly n cubes. Vitaly got upset, demolished everything and left. As he was leaving, he met Petya and told him that there had been three cubes in the room and that he needed another n unit cubes to make his own large cube.

Petya entered the room and saw the messily scattered cubes. He wanted to make it neat and orderly again. But he only knows that there had been three cubes, made of small unit cubes and that Vitaly needed n more unit cubes to make a large one! Help Petya understand, how many ways of sizes abc are there to restore Yaroslav’s, Andrey’s and Roman’s cubes.

Input

The single line of the input contains integer n (1 ≤ n ≤ 1014). We know that all numbers abc are positive integers.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

In the single line print the required number of ways. If it turns out that there isn’t a single way of suitable sizes of abc, print 0.

Examples

input

24

output

1

input

648

output

7

input

5

output

0

input

93163582512000

output

39090

Solution:

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
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
 
using namespace std;
 
int p[424242];
 
int main() {
  long long n;
  cin >> n;
  int ans = 0;
  if (n % 3 == 0) {
    n /= 3;
    int kp = 0;
    for (int d=1;d<=50000;d++)
      if ((4*n) % d == 0) p[kp++] = d;
    for (int a=1;8LL*a*a*a<=n;a++)
      for (int id=0;id<kp;id++) {
        int b = p[id]-a;
        if (b < a) continue;
        if (2LL*b*(a+b)*(a+b) > n) continue;
        long long d = (long long)(a+b)*(a+b)*(a-b)*(a-b)+4LL*(a+b)*n;
        long long dd = sqrt(1.0*d);
        while (dd*dd < d) dd++;
        while (dd*dd > d) dd--;
        if (dd*dd == d) {
          long long c = -a-b+dd/(a+b);
          if (c < 2*b || (c & 1)) continue;
          c >>= 1;
          if (a < b && b < c) ans += 6; else
          if (a == b && b == c) ans += 1;
          else ans += 3;
        }
      }
  }
  cout << ans << endl;
  return 0;
}

Be the first to comment

Leave a Reply

Your email address will not be published.


*