Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- /*
- //zad. 1
- int prime;
- cout << "Enter a number: " << endl;
- cin >> prime;
- bool flag = true;
- for (int i = 2;i < sqrt(prime);i++) {
- if (prime % i == 0) {
- cout << "Num is not prime" << endl;
- flag = false;
- break; //break spira for()
- }
- }
- if (flag) {
- cout << "Num is prime" << endl;
- }
- */
- /*
- //zad.2
- const unsigned N = 200;
- unsigned arr[N] = { 0 };
- int i = 2, j = 0;
- while (i < N) {
- if (arr[i] == 0) {
- arr[i] = i;
- j = i * i;
- while (j < N) {
- arr[j] = 1;
- j += i;
- }
- }
- i++;
- }
- for (int i = 2; i < N; i++) {
- if (arr[i] > 1) {
- cout << arr[i] << "\t";
- }
- }
- */
- //zad.3
- int n, p, x;
- unsigned k = 0;
- cout << "Enter n: ";
- cin >> n;
- cout << endl<< "Please enter a prime number p: ";
- cin >> p;
- x = n;
- while (x%p == 0) {
- k++;
- x /= p;
- }
- if (x == 1) {
- cout << n << " = " << p << " ^ " << k << endl;
- }
- else {
- cout << n << " = " << p << " ^ " << k << " * " << x << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement