Cod sursa(job #2078515)

Utilizator CryshanaGanea Carina Cryshana Data 29 noiembrie 2017 18:01:17
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

const int M=10000;
pair<int,int> ds[M];
int nd;

bool divid (int x)
{
    int i,j,p;
    for(i=0; i<nd ; i++)
        {
            p=0;
            j=ds[i].first;
            while(j<=x)
            {
                p+=(x/j);
                j*=ds[i].first;
            }
            if(p<ds[i].second) return 0;
        }
    return 1;
}


int main()
{
ifstream fin("gfact.in") ;
ofstream fout("gfact.out");
  int p,q,d,pas=1<<30,r=0,x;
  fin>>p>>q;
  int i,j;
  d=2;
  x=p;
  while(d*d<=x&&p!=1)
  {
      if(p%d==0)
      {
          ds[nd].first=d;
          while(p%d==0)
          {
              ds[nd].second++;
              p/=d;
          }
          ds[nd].second*=q;
          nd++;
      }
      d++;
  }
  if(p!=1)
  {
      ds[nd].first=p;
      ds[nd].second=q;
      nd++;
  }
  nd--;
  while(pas!=0)
  {
      if(!divid(r+pas))
        r+=pas;
      pas/=2;
  }
    fout<<r+1;
    return 0;
}