Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #3227
  2. #include<fstream>
  3. #define nebunie 1000006
  4. using namespace std;
  5. ifstream cin("tramvaie.in");
  6. ofstream cout("tramvaie.out");
  7. int phi[nebunie+1];
  8. void problemaproasta()
  9. {
  10. int i,p;
  11. for(i=1;i<=nebunie;i++)phi[i]=i;
  12. for(p=2;p<=nebunie;p++)
  13. {
  14. if(phi[p]==p)
  15. {
  16. phi[p]=p-1;
  17. for(i=2*p;i<=nebunie;i+=p)
  18. {
  19. phi[i]=(phi[i]/p)*(p-1);
  20. }
  21. }
  22. }
  23. }
  24. int n,x,i;
  25. int main()
  26. {
  27. cin>>n;
  28. problemaproasta();
  29. for(i=1;i<=n;i++)
  30. {
  31. cin>>x;
  32. cout<<phi[x]<<" ";
  33. }
  34. return 0;
  35. }
  36.  
  37. #2433
  38. #include<fstream>
  39. #include<cmath>
  40. #include<cstring>
  41. using namespace std;
  42. ifstream cin("cufar.in");
  43. ofstream cout("cufar.out");
  44. int magic(int x,int k)
  45. {
  46. int p=0,i;
  47. while(x%2==0){p=1;x/=2;}
  48. if(p==k)return 2;
  49. else
  50. {
  51. for(i=3;i*i<=x&&p<k;i+=2)
  52. {
  53. if(x%i==0){p++;while(x%i==0)x/=i;}
  54. }
  55. if(x!=1&&p<k)return x;
  56. return i-2;
  57. }
  58. }
  59. int p,n,x,k;
  60. long long s,i;
  61. int main()
  62. {
  63. cin>>p>>n;
  64. if(p==1)
  65. {
  66. cin>>x>>k;
  67. cout<<magic(x,k);
  68. }
  69. else
  70. {
  71. for(i=1;i<=n;i++)
  72. {
  73. cin>>x>>k;
  74. s+=magic(x,k);
  75. }
  76. cout<<s;
  77. }
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement