Răspuns :
#include <iostream>
#include <cmath>
using namespace std;
int cmmdc[5000]={0};
int div1[5000],div2[5000];
int n1,n2;
int ni1,ni2;
int x1,x2;
int prim(int k)
{
int i,ok=true;
for(i=2;i<=k/2;i++)
if(k%i==0)
ok=false;
return ok;
}
void divizor()
{
int k,i;
ni1=n1;
ni2=n2;
for (k=2;k<10;k++)
{
if (prim(k))
{
x1=0;
x2=0;
do{
if (ni1%k==0)
{
x1++;
ni1=ni1/k;
}
} while (ni1%k==0);
div1[k]=x1;
do{
if(ni2%k==0)
{
x2++;
ni2=ni2/k;
}
} while (ni2%k==0);
div2[k]=x2;
}
}
}
int min(int a,int b)
{
if(a<b)
return a;
return b;
}
void afla_cmmdc()
{
int i,j;
for(i=1;i<10000;i++)
if((div1[i]!=0)&&(div2[i]!=0))
cmmdc[i]=min(div1[i],div2[i]);
}
int main()
{
cin>>n1>>n2;
divizor();
afla_cmmdc();
for(int i=1;i<1000;i++)
if (cmmdc[i]!=0)
cout<<cmmdc[i]<<" ";
}