SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void factorize(int number);
  4.  
  5. int get_prime_divider(int number, int from_prime);
  6.  
  7. int main() {
  8.     int number;
  9.     scanf("%d", &number);
  10.  
  11.     if (number <= 1) {
  12.         printf("Error: Number must be greather than 1");
  13.         return -1;
  14.     }
  15.  
  16.     factorize(number);
  17.  
  18.     return 0;
  19. }
  20.  
  21. void factorize(int number) {
  22.     int prime = 2;
  23.     while (number > 1) {
  24.         prime = get_prime_divider(number, prime);
  25.         number = number / prime;
  26.         printf("%d \r\n", prime);
  27.     }
  28. }
  29.  
  30. int get_prime_divider(int number, int from_prime) {
  31.     if (from_prime == 2)
  32.         if ((number & 1) == 0)return 2;
  33.         else from_prime++;
  34.  
  35.     for (int i = from_prime; i * i <= number; i += 2)
  36.         if (number % i == 0) return i;
  37.  
  38.     return number;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top