1 #include<stdio.h> 2 #include<string.h> 3 long long int ans,n; 4 int cnt,a[25]; 5 long long int gcd(long long int x,long long int y) 6 { 7 if (y==0) return x; 8 return gcd(y,x%y); 9 } 10 void dfs(int now,int flag,long long bei) 11 { 12 if (flag) ans+=n/bei; 13 else ans-=n/bei; 14 for (int i=now+1;i<=cnt;i++) 15 dfs(i,1-flag,a[i]/gcd(a[i],bei)*bei); 16 } 17 int main() 18 { 19 int m,i; 20 while (~scanf("%I64d%d",&n,&m)) 21 { 22 cnt=0; 23 for (i=1;i<=m;i++) 24 { 25 scanf("%d",&a[i]); 26 if (a[i]!=0) {cnt++; a[cnt]=a[i]; } 27 } 28 ans=0; n--; 29 for (i=1;i<=cnt;i++) dfs(i,1,a[i]); 30 printf("%I64d\n",ans); 31 } 32 }
转载于:https://www.cnblogs.com/xiao-xin/articles/3956827.html