acobzew

problem8_poly

Sep 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. unsigned int f(int n)
  6. {
  7. unsigned int ans = 0, factors;
  8. int tmp;
  9. for (int x = 0; x < n; x++)
  10. {
  11. tmp = x;
  12. factors = 0;
  13. if (tmp == 1)
  14. factors++;
  15. for (int i = 2; i <= sqrt(tmp); i++)
  16. {
  17. while (tmp % i == 0)
  18. {
  19. factors++;
  20. tmp /= i;
  21. if (factors > 2)
  22. break;
  23. }
  24. }
  25. if (tmp != 1)
  26. factors++;
  27.  
  28. if (factors == 2)
  29. ans++;
  30. }
  31. return ans;
  32. }
  33.  
  34. int main()
  35. {
  36. printf("%d\n", f(30));
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment