Advertisement
andruhovski

TaskE

May 16th, 2016
1,685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. // Task04.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. void primeFactors(int n);
  10. bool isPrime3Factors(int n);
  11.  
  12. int _tmain(void)
  13. {
  14.     int count = 0;
  15.     int a,b;
  16.         cin >> a >> b;
  17.     for (size_t i = a; i <= b; i++)
  18.     {
  19.         if (isPrime3Factors(i))
  20.             count++;
  21.         ;
  22.     }
  23.     cout << count << endl;
  24.     return 0;
  25. }
  26.  
  27. bool isPrime3Factors(int n)
  28. {
  29.     int count = 0;
  30.     while (n % 2 == 0)
  31.     {
  32.         if (++count > 3) return false;
  33.         n = n / 2;
  34.     }
  35.  
  36.     for (int i = 3; i <= sqrt(n); i = i + 2)
  37.     {  
  38.         while (n%i == 0)
  39.         {
  40.             if (++count > 3) return false;
  41.             n = n / i;
  42.         }
  43.     }
  44.  
  45.     if (n > 2) ++count;
  46.     return count == 3;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement