PTA (Basic Level) 1087. How many different values

When the natural number n sequentially capturing l, 2,3, ......, N , the formula ⌊ n / 2⌋ ⌊ + n / 3⌋ + ⌊ n / 5⌋ how many different values are? (Note: ⌊ x ⌋ is the floor function, represents no more than x the maximum natural number, i.e., x integer part.)

Input formats:

Input gives a positive integer N (2 ≦ N ≤104).

Output formats:

The number of different values ​​of the output face formula title in a row to take.

Sample input:
2017
Sample output:
1480
Thinking
  • Fully illustrated STLthe importance to master a lot of it on the less amount of code ...
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<int> s;
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        s.insert(i/2+i/3+i/5);
    cout << s.size();
    return 0;
}
Quote

https://pintia.cn/problem-sets/994805260223102976/problems/1038429191091781632

Guess you like

Origin www.cnblogs.com/MartinLwx/p/11614294.html