Cod sursa(job #2396467)
| Utilizator | Data | 3 aprilie 2019 15:30:20 | |
|---|---|---|---|
| Problema | GFact | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 1.11 kb |
#include <fstream>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int nr,q,j,i,d[100001],p[100001];
void desc(int n)
{
int x;
while(n%2==0&&n)
{
d[0]=2;
p[2]++;
n=n/2;
}
x=3;
while(n)
{
if(n%x==0)
{
d[++nr]=x;
while(n%x==0&&n!=0)
{
n=n/x;
p[x]++;
}
p[x]*=q;
}
x+=2;
}
}
void desc1(int n)
{
int x;
while(n%2==0&&n)
{
p[2]--;
n=n/2;
}
x=3;
while(n)
{
if(n%x==0)
{
while(n%x==0&&n)
{
n=n/x;
p[x]--;
}
}
x+=2;
}
}
int main()
{int we;
fin>>we>>q;
desc(we);
p[2]--;
p[3]--;
for(i=4; i<=2000000000; i++)
{
desc1(i);
for(j=1; j<=nr; j++)
if(p[d[j]]) break;
if(j>nr)
{
fout<<i;
break;
}
}
return 0;
}
