思路:

就二进制枚举哪些数,然后取最小公倍数

搞一搞

//By SiriusRen
#include <cstdio>
using namespace std;
#define int long long
int n,r,m,s[15];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
signed main(){
    while(~scanf("%lld%lld",&n,&r)){
        int ans=0;n--;m=0;
        for(int i=0;i<r;i++){
            scanf("%lld",&s[m]);
            if(s[m])m++;
        }
        for(int i=1;i<(1<<m);i++){
            int tmp=1,t=0;
            for(int j=0;j<m;j++){
                if(i&(1<<j)){
                    t++,tmp=tmp*s[j]/gcd(tmp,s[j]);
                }
            }
            t=t&1?1:-1;
            ans+=t*n/tmp;
        }
        printf("%lld\n",ans);
    }
}

 

相关文章:

  • 2021-06-25
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
猜你喜欢
  • 2022-12-23
  • 2022-02-16
  • 2022-01-28
  • 2022-12-23
  • 2022-01-16
  • 2021-07-10
相关资源
相似解决方案