同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;}1284 2 3 5 7的倍數基準時間限制: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示例10Output示例1
新聞熱點
疑難解答