Editorial for Số có 3 ước


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Lời giải dưới đây chỉ mang tính chất tham khảo. Vui lòng không sao chép để AC bài tập.

#include<bits/stdc++.h>
using namespace std;
int check(long long n)
{
    if(n < 2)   return false;
    for(int i = 2; i * i <= n;i++)
        if(n % i == 0)
            return false;
    return true;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

   long long a,b,d1=0,d2=0;
   cin>>a>>b;
   for(int i = 1; i * i <= b;i++)
   {
       if(check(i)) d1++;
   }
   for(int i = 1; i * i <= a - 1;i++)
   {
       if(check(i)) d2++;
   }
   cout<<d1 - d2;
}



Comments

There are no comments at the moment.