[ create a new paste ] login | about

Link: http://codepad.org/ydEmp3dk    [ raw code | output | fork ]

C++, pasted on Jun 13:
#include <iostream>
using namespace std;

class Solution{
public:
   int nextTPH(int &t, int &p, int &h)
   {    
        t++;
        int Tri = 0;
        for (;;t++)
        {
            Tri = t * (t + 1)/2;
            p = (1 + (int) sqrt(1 + 24 * Tri))/6;
            int Pen = p * (3 * p -1)/2;
            h = (1 + (int) sqrt(1 + 8 * Tri))/4;
            int Hex = h * ( 2 * h - 1);
            if (Pen == Tri && Hex == Tri) return Tri;
        }
        return Tri;
   }
};

int main(){
    Solution test;

    int t = 285;
    int p = 165;
    int h = 143;
    
    cout << test.nextTPH(t, p, h) <<endl;
    return 0;
}


Output:
1
Timeout


Create a new paste based on this one


Comments: