题目:https://pintia.cn/problem-sets/994805260223102976/problems/1038429191091781632
这道题要注意哈希表开得大一点,不然会出现段错误,另一个就是哈希表的遍历从0开始
使用set会更方便
代码
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;const int maxn = 1000010;int hash[maxn];int main(){int n;fill(hash, hash + maxn, 0);scanf("%d", &n);for(int i = 1;i <= n; i++){int temp = i / 2 + i / 3 + i / 5;hash[temp]++;}int count = 0;for(int i = 0; i <= maxn; i++){if(hash[i] > 0)count++;}printf("%d",count);}
