Advertisement
a53

cmmdc0

a53
Feb 24th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("cmmdc0.in");
  4. ofstream g("cmmdc0.out");
  5. int n,p[5]={0,2,3,5,7},nr_exp_aflati=0,ex[5],ed[5],ok[5],sol[5],x,d,produs=1;
  6.  
  7. int main()
  8. {
  9. f>>n;
  10. for(int i=1;i<=n;++i)
  11. {
  12. f>>x>>d;
  13. for(int j=1;j<=4;++j)
  14. if(ok[j]==0)
  15. {
  16. ex[j]=0 ;
  17. while(x%p[j]==0)
  18. ++ex[j],x/=p[j];
  19. ed[j]=0;
  20. while(d%p[j]==0)
  21. ++ed[j],d=d/p[j];
  22. if(ex[j]>ed[j])
  23. ok[j]=1,sol[j]=ed[j],++nr_exp_aflati;
  24. else
  25. if(ex[j]>sol[j])
  26. sol[j]=ex[j];
  27. }
  28. if(nr_exp_aflati==4)
  29. break;
  30. }
  31. for(int j=1;j<=4;++j)
  32. for(int i=1;i<=sol[j];++i)
  33. produs*=p[j];
  34. g<<produs;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement