标签:ase bsp 个数 otto rip php example 包含 思路
Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8997 Accepted Submission(s): 2697
#include <cstdio> using namespace std; const int maxn=15; int num,m; long long n,ans,a[maxn]; long long gcd(long long a,long long b) { return b==0?a:gcd(b,a%b); } void dfs(int i, long long lcm , int id) { lcm = a[i]/(gcd(a[i],lcm))*lcm; if(id%2) ans += (n-1)/lcm; else ans -= (n-1)/lcm; for(int j=i+1;j<=num;j++) dfs(j,lcm,id+1); } int main() { while(scanf("%lld %d",&n,&m)!=EOF) { int t; num=0; for(int i=1;i<=m;i++) { scanf("%d",&t); if(t) a[++num] = t; } ans=0; for(int i=1;i<=num;i++) { dfs(i,a[i],1); } printf("%lld\n",ans); } }
HDU-1796 How many integers can you find(组合数学、dfs)
标签:ase bsp 个数 otto rip php example 包含 思路
原文地址:http://www.cnblogs.com/WWkkk/p/7399330.html