传送门:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1284
容斥原理:从反面考虑,n-(2的倍数||3的倍数||5的倍数||7的倍数)
#include<iostream> #include<algorithm> #include<vector> #include<string.h> #include<map> using namespace std; typedef long long ll; const int MAX = 5e4 + 5; ll n, t; int main() { cin >> n; ll a, b, c, d; a = n / 2 + n / 3 + n / 5 + n / 7; b = n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35; c = n / 30 + n / 42 + n / 105+n/70; d = n / 210; cout << n - a + b - c + d << endl; return 0; }
原文:http://www.cnblogs.com/Egoist-/p/7622419.html