题目:https://pintia.cn/problem-sets/994805260223102976/problems/1038429191091781632
这道题要注意哈希表开得大一点,不然会出现段错误,另一个就是哈希表的遍历从0开始
使用set会更方便

代码

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<algorithm>
  4. using namespace std;
  5. const int maxn = 1000010;
  6. int hash[maxn];
  7. int main(){
  8. int n;
  9. fill(hash, hash + maxn, 0);
  10. scanf("%d", &n);
  11. for(int i = 1;i <= n; i++){
  12. int temp = i / 2 + i / 3 + i / 5;
  13. hash[temp]++;
  14. }
  15. int count = 0;
  16. for(int i = 0; i <= maxn; i++){
  17. if(hash[i] > 0)count++;
  18. }
  19. printf("%d",count);
  20. }