同hdoj 1796 点击打开链接
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[4] = {2, 3, 5, 7};
ll n, ans;
void dfs(ll cur, ll lcm, ll id)
{
lcm = a[cur]/__gcd(a[cur], lcm)*lcm;
if(id%2) ans -= n/lcm;
else ans += n/lcm;
for(int i = cur+1; i < 4; i++)
dfs(i, lcm, id+1);
}
int main(void)
{
while(cin >> n)
{
ans = n;
for(int i = 0; i < 4; i++)
dfs(i, a[i], 1);
printf("%lld\n", ans);
}
return 0;
}
基准时间限制:1 秒 空间限制:131072 KB 分值: 5
难度:1级算法题
给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数。 例如N = 10,只有1不是2 3 5 7的倍数。
Input
输入1个数N(1 <= N <= 10^18)。
Output
输出不是2 3 5 7的倍数的数共有多少。
Input示例
10
Output示例
1