[ create a new paste ] login | about

Link: http://codepad.org/MRFs7ERl    [ 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)
   {    
        h++;
        int Hex = 0;
        for (;;h++)
        {
            int Hex = h * ( 2 * h - 1);
            
            t = (-1 + (int) sqrt(1 + 8 * Hex))/2;
            int Tri = t * (t + 1)/2;
            p = (1 + (int) sqrt(1 + 24 * Hex))/6;
            int Pen = p * (3 * p -1)/2;
            
            
            if (Pen == Tri && Hex == Tri) return Tri;
        }
        return Hex;
   }
};

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: