标签:des blog http io ar os sp java for
Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4473 Accepted Submission(s): 1284
http://acm.hdu.edu.cn/showproblem.php?pid=1796
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
#define LL long long
LL n,m,a[20],ans;
LL gcd(LL a,LL b)
{
return b?gcd(b,a%b):a;
}
void dfs(LL id,LL flag,LL LCM)
{
LCM=a[id]*LCM/gcd(a[id],LCM);
if(flag)
ans=ans+n/LCM;
else
ans=ans-n/LCM;
for(LL i=id+1;i<=m;i++)
dfs(i,!flag,LCM);
}
int main()
{
while(scanf("%lld%lld",&n,&m)!=EOF)
{
ans=0;
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
if(!a[i])
i--,m--;
}
n--;
for(int i=1;i<=m;i++)
dfs(i,1,a[i]);
printf("%lld\n",ans);
}
return 0;
}
标签:des blog http io ar os sp java for
原文地址:http://www.cnblogs.com/a972290869/p/4101121.html