Advertisement
AlexAvram

exp #2141

Feb 4th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. ifstream f("exp.in");
  6. ofstream g("exp.out");
  7. bool ciur[30001];
  8. short h=0, nrp[3500],pw[3500];
  9. void eratostene()
  10. {
  11. int i, j;
  12. ciur[0]=ciur[1]=1;
  13. for (i=2; i<=173; ++i)
  14. {
  15. if(!ciur[i])
  16. {
  17. for (j=i*i; j<=30001; j+=i)
  18. ciur[j]=1;
  19. }
  20. }
  21. for(i=1; i<=30000; ++i)
  22. if(!ciur[i])
  23. nrp[++h]=i;
  24. }
  25. void factp(int a)
  26. {
  27. int f, p, k=0;
  28. f=nrp[++k];
  29. while (a>1)
  30. {
  31. p=0;
  32. while (a%f==0)
  33. a/=f, ++p;
  34. pw[k]+=p;
  35. f=nrp[++k];
  36. }
  37. }
  38. int main()
  39. {
  40. eratostene();
  41. cout<<nrp[h];
  42. short ord, n; int x;
  43. f>>ord>>n;
  44. short i;
  45. for (i=1; i<=n; ++i)
  46. {
  47. f>>x;
  48. factp(x);
  49. }
  50.  
  51. for (i=1; i<=h; ++i)
  52. {
  53. if(pw[i]%ord)
  54. {
  55. g<<0;
  56. return 0;
  57. }
  58. else
  59. pw[i]/=ord;
  60. }
  61. g<<1<<'\n';
  62. for (i=1; i<=h; ++i)
  63. if(pw[i])
  64. g<<nrp[i]<<" "<<pw[i]<<'\n';
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement