Cod sursa(job #1734249)

Utilizator alittlezzCazaciuc Valentin alittlezz Data 26 iulie 2016 21:19:10
Problema GFact Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <fstream>
#include <math.h>
#include <algorithm>
#include <unordered_map>

using namespace std;
#define ll long long
#define llu long long unsigned
#define pb push_back
#define mp make_pair

string problemName = "gfact";
string inFile = problemName+".in";
string outFile = problemName+".out";
ifstream fin(inFile.c_str());
ofstream fout(outFile.c_str());

unordered_map <int, int> need;

void desc(int p, int q){
    int i,aux,c;
    c = 0;
    while(p%2 == 0){
        c++;
        p /= 2;
    }
    if(c){
        need[2] = c*q;
    }
    for(i = 3;i*i <= p;i += 2){
        if(p%i == 0){
            c = 0;
            while(p%i == 0){
                c++;
                p /= i;
            }
            need[i] = c*q;
        }
    }
    if(p > 1){
        need[p] = q;
    }
}

int main(){
    int p,q,i,aux,c,target,x;
    fin>>p>>q;
    desc(p, q);
    int mn = 2e9;
    for(auto it : need){
        x = it.first;
        target = it.second;
        c = 0;
        for(i = x;;i += x){
            aux = i;
            while(aux%x == 0){
                c++;
                aux /= x;
            }
            if(c >= target){
                mn = min(mn, i);
                break;
            }
        }
    }
    fout<<mn;
    return 0;
}