Pat B grade 1087 How many different values ​​(20 points) solution

pat B grade 1087 How many different values ​​(20 points) solution

题描述

pat乙级1087 有多少不同的值 (20 分)题目描述

算法设计

题Simple, traverse 1~N according to the description of the problem. Put the value of ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ to unordered<int>set Then output the number of elements in the set.

C++ code

#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    scanf("%d",&N);
    unordered_set<int>s;
    for(int i=1;i<=N;++i)
        s.insert(i/2+i/3+i/5);
    printf("%d",s.size());
    return 0;
}