fork download
  1. #include<stdio.h>
  2. #define gc getchar
  3. typedef long long ll;
  4. inline ll input() {
  5. char c = gc();
  6. while(c<'0' || c>'9') c = gc();
  7. ll ret = 0;
  8. while(c>='0' && c<='9') {
  9. ret = 10 * ret + c - 48;
  10. c = gc();
  11. }
  12. return ret;
  13. }
  14. ll func(ll a,ll b)
  15. {
  16. if(b==0)
  17. return a;
  18. else
  19. return func(b,a%b);
  20. }
  21. int main()
  22. {
  23. ll n,k,i,j,b,count=0,ans=0,cc,t,ar[21];;
  24. n=input();
  25. k=input();
  26. for(i=0;i<k;i++)
  27. ar[i]=input();
  28. t=(1<<k);
  29. for(i=1;i<t;i++)
  30. {
  31. b=1;count=0;
  32. for(j=0;j<k;j++)
  33. {
  34. if(i&(1<<j))
  35. {
  36. b=((b*ar[j])/func(b,ar[j]));
  37. count++;
  38. }
  39. }
  40. if(count%2!=0)
  41. ans=ans+(n/b);
  42. else
  43. ans=ans-(n/b);
  44. }
  45. printf("%lf\n",((double)((double)(n-ans)/n)*100));
  46. return 0;
  47.  
  48. }
Success #stdin #stdout 0s 3416KB
stdin
10 3 3 2 5
stdout
20.000000