1087 How many different values are there (20point(s))

1087 How many different values ​​are there (20point(s))

When the natural number n is 1, 2, 3,..., N in turn, how many different values ​​are there in the formula ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋? (Note: ⌊x⌋ is a rounding function, which means not exceeding the largest natural number of x, that is, the integer part of x.)

Input format:
Input gives a positive integer N (2≤N≤10
​4
​​).

Output format:
output the number of different values ​​taken by the formula in the question surface in one line.

Input sample:
2017
Output sample:
1480

#include<bits/stdc++.h>
using namespace std;
int hashTable[11000]={
    
    false};
int main(){
    
    
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i){
    
    
        int num=i/2+i/3+i/5;
        if(!hashTable[num]){
    
    
            hashTable[num]=true;
            ans++;
        }
    }
    cout<<ans<<endl;
}
#include<bits/stdc++.h>
using namespace std;
int hashTable[11000]={
    
    false};
int main(){
    
    
    int n;
    cin>>n;
    set<int> s;
    for(int i=1;i<=n;++i)
        s.insert(i/2+i/3+i/5);
    cout<<s.size()<<endl;
}

Guess you like

Origin blog.csdn.net/weixin_44970602/article/details/112277125