Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- unsigned int f(int n)
- {
- unsigned int ans = 0, factors;
- int tmp;
- for (int x = 0; x < n; x++)
- {
- tmp = x;
- factors = 0;
- if (tmp == 1)
- factors++;
- for (int i = 2; i <= sqrt(tmp); i++)
- {
- while (tmp % i == 0)
- {
- factors++;
- tmp /= i;
- if (factors > 2)
- break;
- }
- }
- if (tmp != 1)
- factors++;
- if (factors == 2)
- ans++;
- }
- return ans;
- }
- int main()
- {
- printf("%d\n", f(30));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment