Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. /*
  7.  
  8. //zad. 1
  9. int prime;
  10. cout << "Enter a number: " << endl;
  11. cin >> prime;
  12.  
  13. bool flag = true;
  14.  
  15.  
  16. for (int i = 2;i < sqrt(prime);i++) {
  17.  
  18. if (prime % i == 0) {
  19. cout << "Num is not prime" << endl;
  20. flag = false;
  21. break; //break spira for()
  22. }
  23.  
  24. }
  25.  
  26. if (flag) {
  27. cout << "Num is prime" << endl;
  28. }
  29.  
  30. */
  31.  
  32.  
  33. /*
  34.  
  35. //zad.2
  36. const unsigned N = 200;
  37. unsigned arr[N] = { 0 };
  38.  
  39. int i = 2, j = 0;
  40.  
  41. while (i < N) {
  42. if (arr[i] == 0) {
  43. arr[i] = i;
  44. j = i * i;
  45.  
  46. while (j < N) {
  47. arr[j] = 1;
  48. j += i;
  49. }
  50. }
  51. i++;
  52. }
  53.  
  54. for (int i = 2; i < N; i++) {
  55. if (arr[i] > 1) {
  56. cout << arr[i] << "\t";
  57. }
  58. }
  59.  
  60.  
  61.  
  62. */
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. //zad.3
  70. int n, p, x;
  71. unsigned k = 0;
  72.  
  73. cout << "Enter n: ";
  74. cin >> n;
  75.  
  76. cout << endl<< "Please enter a prime number p: ";
  77. cin >> p;
  78.  
  79. x = n;
  80. while (x%p == 0) {
  81. k++;
  82. x /= p;
  83. }
  84.  
  85. if (x == 1) {
  86. cout << n << " = " << p << " ^ " << k << endl;
  87. }
  88. else {
  89. cout << n << " = " << p << " ^ " << k << " * " << x << endl;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement