Cod sursa(job #1883852)

Utilizator icansmileSmileSmile icansmile Data 18 februarie 2017 11:37:13
Problema GFact Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;

long long find(long long P, long long Q){
    long long counter = 0;
    for(long long i = 1; i <= INT64_MAX; i++ )
    {
        if( i % P == 0){
            counter += i/P;
            if(counter == Q){
                return i;
            }
        }
//        if(A % i == 0)
//        {
//            tempB = tempB*i;
//            if(tempB % A == 0)
//            {
//                return i;
//            }
//        }
    }
    return -1;
}

int main() {
    long long P,Q;

    ifstream in("gfact.in");
    ofstream out("gfact.out");

    in >> P >> Q;

    out << find(P,Q);

    return 0;
}