andruhovski icon

TaskE

andruhovski | PRO | 05/16/16 12:48:53 PM UTC | 0 ⭐ | 2530 👁️ | Never ⏰ | []
C++ |

710 B

|

None

|

0 👍

/

0 👎

// Task04.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
 
void primeFactors(int n);
bool isPrime3Factors(int n);
 
int _tmain(void)
{
    int count = 0;
    int a,b;
        cin >> a >> b;
    for (size_t i = a; i <= b; i++)
    {
        if (isPrime3Factors(i))
            count++;
        ;
    }
    cout << count << endl;
    return 0;
}
 
bool isPrime3Factors(int n)
{
    int count = 0;
    while (n % 2 == 0)
    {
        if (++count > 3) return false;
        n = n / 2;
    }
 
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {   
        while (n%i == 0)
        {
            if (++count > 3) return false;
            n = n / i;
        }
    }
 
    if (n > 2) ++count;
    return count == 3;
}

Comments