zoukankan      html  css  js  c++  java
  • UVa10325

    容斥原理,求会被去掉的数字的个数,在ai组成的集合中用最小公倍数作为除数。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <cstdlib>
     6 #include <climits>
     7 #include <sstream>
     8 #include <fstream>
     9 #include <cstdio>
    10 #include <string>
    11 #include <vector>
    12 #include <queue>
    13 #include <cmath>
    14 #include <stack>
    15 #include <map>
    16 #include <set>
    using namespace std;
    17 int gcd(int a,int b) 18 { 19 int r=0; 20 while(b!=0) 21 { 22 r=a%b; 23 a=b; 24 b=r; 25 } 26 return(a); 27 } 2829 int main() 30 { 31 long long n,m,a[30],i,sum,msk,mult,bits,cur; 32 while(scanf("%lld%lld",&n,&m)!=EOF) 33 { 34 for(i=0;i<m;i++) 35 scanf("%lld",&a[i]); 36 sum = 0; 37 for (msk=1;msk<(1<<m);++msk) 38 { 39 mult=1,bits=0; 40 for(int i=0;i<m;++i) 41 if(msk&(1<<i)) 42 { 43 ++bits; 44 mult=mult*a[i]/gcd(max(mult,a[i]),min(mult,a[i])); 45 } 46 // printf("%d\n",mult); 47 cur=n/mult; 48 if(bits%2==1) 49 sum+=cur; 50 else 51 sum-=cur; 52 } 53 printf("%lld\n",n-sum); 54 } 55 return 0; 56 }
  • 相关阅读:
    A promise tomorrow is worth a lot less than trying today.
    时间相关函数
    JAVA中日期格式转换各个字母代表含义
    参考链接
    修饰器
    最新提案
    ArrayBuffer
    读懂 ECMAScript 规格
    使用markdown写博客
    linux系统界面转换
  • 原文地址:https://www.cnblogs.com/Acgsws/p/3131761.html
Copyright © 2011-2022 走看看