标签:
Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5605 Accepted Submission(s): 1602
/* *********************************************** Author :pk29 Created Time :2015/8/20 10:01:50 File Name :4.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bool cmp(int a,int b){ return a>b; } ll n,m; ll arr[20]; ll gcd(ll a,ll b){ return a==0?b:gcd(b%a,a); } ll lcm(ll a,ll b){ ll c=gcd(a,b); return a*b/c; } ll solve(){ ll sum=0; n--; for(int i=1;i<(1<<m);i++){ int bits=0; ll mul=1; for(int j=0;j<m;j++){ if(i&(1<<j)){ bits++; mul=lcm(arr[j],mul); } } if(bits&1)sum+=n/mul; else sum-=n/mul; } return sum; } int main() { #ifndef ONLINE_JUDGE //freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); while(cin>>n>>m){ int cnt=0,x; for(int i=0;i<m;i++){ cin>>x; if(x!=0)arr[cnt++]=x; } m=cnt--; cout<<solve()<<endl; } return 0; }
HDU 1796 How many integers can you find
标签:
原文地址:http://www.cnblogs.com/pk28/p/4744549.html