Skip to content

Commit 7f5781d

Browse files
committed
Almost Prime
1 parent 1fc9023 commit 7f5781d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Diff for: 26A.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//4240326 Aug 7, 2013 5:13:59 PM fuwutu 26A - Almost Prime GNU C++0x Accepted 30 ms 0 KB
2+
#include <cstdio>
3+
4+
int main()
5+
{
6+
int n, amount(0);
7+
scanf("%d", &n);
8+
9+
bool b[3001] = {false};
10+
int pfactors[3001] = {0};
11+
for (int i = 2; i <= n; ++i)
12+
{
13+
if (!b[i])
14+
{
15+
for (int j = i + i; j <= n; j += i)
16+
{
17+
b[j] = true;
18+
pfactors[j] += 1;
19+
}
20+
}
21+
22+
if (pfactors[i] == 2)
23+
{
24+
amount += 1;
25+
}
26+
}
27+
printf("%d\n", amount);
28+
return 0;
29+
}

0 commit comments

Comments
 (0)