From 7f5781d6d75fb84d716a26d723cfa2eb8778f33c Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 3 May 2024 21:13:38 +0530 Subject: [PATCH] Almost Prime --- 26A.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/26A.cpp b/26A.cpp index e69de29..844f019 100644 --- a/26A.cpp +++ b/26A.cpp @@ -0,0 +1,29 @@ +//4240326 Aug 7, 2013 5:13:59 PM fuwutu 26A - Almost Prime GNU C++0x Accepted 30 ms 0 KB +#include + +int main() +{ + int n, amount(0); + scanf("%d", &n); + + bool b[3001] = {false}; + int pfactors[3001] = {0}; + for (int i = 2; i <= n; ++i) + { + if (!b[i]) + { + for (int j = i + i; j <= n; j += i) + { + b[j] = true; + pfactors[j] += 1; + } + } + + if (pfactors[i] == 2) + { + amount += 1; + } + } + printf("%d\n", amount); + return 0; +} \ No newline at end of file