fork download
  1. //package com.company;
  2.  
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6. class Main implements Runnable {
  7. int size[];
  8. static int e9 = 1000000007;
  9. int max = Integer.MIN_VALUE;
  10. long max1 = Long.MIN_VALUE;
  11. long min1 = Long.MAX_VALUE;
  12. long fib[][];
  13. static class FastReader {
  14.  
  15. public FastReader() {
  16. br = new BufferedReader(new
  17. }
  18.  
  19. String next() {
  20. while (st == null || !st.hasMoreElements()) {
  21. try {
  22. st = new StringTokenizer(br.readLine());
  23. } catch (IOException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. return st.nextToken();
  28. }
  29.  
  30. int nextInt() {
  31. return Integer.parseInt(next());
  32. }
  33.  
  34. long nextLong() {
  35. return Long.parseLong(next());
  36. }
  37.  
  38. double nextDouble() {
  39. return Double.parseDouble(next());
  40. }
  41.  
  42. String nextLine() {
  43. String str = "";
  44. try {
  45. str = br.readLine();
  46. } catch (IOException e) {
  47. e.printStackTrace();
  48. }
  49. return str;
  50. }
  51. }
  52. int parent[];
  53. int rank[];
  54. ArrayList<ArrayList<Integer>> arrayLists;
  55. ArrayList<Integer> arr[];
  56. long fib1[][];
  57. long r[];
  58. int n;
  59. int m;
  60. long co=0;
  61. long size1[];
  62. long v[];
  63. public static void main(String[] args) throws IOException {
  64. new Thread(null,new Main(),"Main",1<<28).start();
  65. }
  66.  
  67. public void run(){
  68. // FastReader scanner = new FastReader();
  69. Scanner scanner = new Scanner(System.in);
  70. // BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
  71. // String s;
  72. PrintWriter printWriter = new PrintWriter(System.out);
  73. // System.out.println(1<<6);
  74. // long t=scanner.nextLong();
  75.  
  76.  
  77.  
  78. //Solution Starts
  79.  
  80.  
  81. high:while (scanner.hasNext()) {
  82. long n=scanner.nextLong();
  83. int m=scanner.nextInt();
  84. long arr[]=new long[m];
  85. long ans=0;
  86. long ans1=1;
  87. for (int i = 0; i < m; i++) {
  88. long a=scanner.nextLong();
  89. arr[i]=a;
  90. ans1=ans1*a;
  91. }
  92. for (int i = 0; i < m; i++) {
  93. ans=gcd(ans,arr[i]);
  94. }
  95. long lcm=ans1/ans;
  96. // System.out.println(lcm);
  97. long or=0;
  98. for (int i = 1; i <=lcm ; i++) {
  99. boolean w=true;
  100. for (int j = 0; j < m; j++) {
  101. if(i%arr[j]==0){
  102. w=false;
  103. break;
  104. }
  105. }
  106. if(w){
  107. or++;
  108. }
  109. }
  110. long u=n/lcm;
  111. or=or*u;
  112. long y=u*lcm;
  113. for (long i = y+1; i <n; i++) {
  114. boolean w=true;
  115. for (int j = 0; j < m; j++) {
  116. if(i%arr[j]==0){
  117. w=false;
  118. break;
  119. }
  120. }
  121. if(w){
  122. or++;
  123. }
  124. }
  125. printWriter.println(or);
  126. }
  127. printWriter.flush();
  128. }
  129.  
  130. //Solution Ends
  131.  
  132.  
  133.  
  134.  
  135. static long mod=1_000_000_007;
  136. public long mul(long a, long b) {
  137. // System.out.println(a+" "+b);
  138. return ((a)%mod*(b)%mod);
  139. }
  140. public long fact(int x) {
  141. long ans=1;
  142. for (int i=2; i<=x; i++) ans=mul(ans, i);
  143. return ans;
  144. }
  145. public long fastPow(long base, long exp) {
  146. if (exp==0) return 1;
  147. long half=fastPow(base, exp/2);
  148. if (exp%2==0) return mul(half, half);
  149. return mul(half, mul(half, base));
  150. }
  151. public long modInv(long x) {
  152. return fastPow(x, mod-2);
  153. }
  154. public long nCk(int n, int k) {
  155. return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n-k))));
  156. }
  157. public void parent(int n){
  158. parent=new int[n+1];
  159. size=new int[n+1];
  160. rank=new int[n+1];
  161. for (int i = 0; i <=n; i++) {
  162. parent[i]=i;
  163. rank[i]=0;
  164. // size[i]=1;
  165. }
  166. }
  167. public void union(int i,int j){
  168. int root1=find(i);
  169. int root2=find(j);
  170. // if(root1 != root2) {
  171. // parent[root2] = root1;
  172. //// sz[a] += sz[b];
  173. // }
  174. if(root1==root2){
  175. return;
  176. }
  177. if(rank[root1]>rank[root2]){
  178. parent[root2]=root1;
  179. size[root1]+=size[root2];
  180. }
  181. else if(rank[root1]<rank[root2]){
  182. parent[root1]=root2;
  183. size[root2]+=size[root1];
  184. }
  185. else{
  186. parent[root2]=root1;
  187. rank[root1]+=1;
  188. size[root1]+=size[root2];
  189. }
  190. }
  191. public int find(int p){
  192. if(parent[p]!=p){
  193. if(parent[p]==-1){
  194. return parent[p];
  195. }
  196. parent[p]=find(parent[p]);
  197. }
  198. return parent[p];
  199. }
  200. public double dist(double x1,double y1,double x2,double y2){
  201. double e=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
  202. double e1=Math.sqrt(e);
  203. return e1;
  204. }
  205. public void make(int p){
  206. parent[p]=p;
  207. rank[p]=1;
  208. }
  209. Random rand = new Random();
  210. public void sort(int[] a, int n) {
  211. for (int i = 0; i < n; i++) {
  212. int j = rand.nextInt(i + 1);
  213. int tmp = a[i];
  214. a[i] = a[j];
  215. a[j] = tmp;
  216. }
  217. Arrays.sort(a, 0, n);
  218. }
  219. public long gcd(long a,long b){
  220. if(b==0){
  221. return a;
  222. }
  223. return gcd(b,a%b);
  224. }
  225. // public void dfs(ArrayList<Integer> arrayList){
  226. // for (int i = 0; i < arrayList.size(); i++) {
  227. // if(v1[arrayList.get(i)]==false){
  228. // v1[arrayList.get(i)]=true;
  229. // dfs(arrayLists.get(i));
  230. // }
  231. // }
  232. // }
  233. public double fact(double h){
  234. double sum=1;
  235. while(h>=1){
  236. sum=(sum%e9)*(h%e9);
  237. h--;
  238. }
  239. return sum%e9;
  240. }
  241. public long primef(double r){
  242. long c=0;
  243. long ans=1;
  244. while(r%2==0){
  245. c++;
  246. r=r/2;
  247. }
  248. if(c>0){
  249. ans*=2;
  250. }
  251. c=0;
  252. // System.out.println(ans+" "+r);
  253. for (int i = 3; i <=Math.sqrt(r) ;i+=2) {
  254. while(r%i==0){
  255. // System.out.println(i);
  256. c++;
  257. r=r/i;
  258. }
  259. if(c>0){
  260. ans*=i;
  261. }
  262. c=0;
  263. }
  264. if(r>2){
  265. ans*=r;
  266. }
  267. return ans;
  268. }
  269. public long divisor(double r,long n,long k){
  270. long c=0;
  271. // if(n==3)
  272. // System.out.println(r+" "+n+" "+k+" "+"l");
  273. for (int i =2; i <=Math.sqrt(r)&&i<k&&i<n; i++) {
  274. if(r%i==0){
  275. if(r/i==i){
  276. c++;
  277. }
  278. else{
  279. if(r/i<n){
  280. c+=2;
  281. }else{
  282. c++;
  283. }
  284. }
  285. }
  286. }
  287. return c;
  288. }
  289. }
  290. class Pair {
  291. int x;
  292. int y;
  293. int z;
  294. public Pair(int x,int y) {
  295. this.x = x;
  296. this.y = y;
  297. // this.z=z;
  298. }
  299.  
  300. // @Override
  301. // public int hashCode() {
  302. // int hash = 37;
  303. // return this.x * hash + this.y;
  304. // }
  305. //
  306. // @Override
  307. // public boolean equals(Object o1) {
  308. // if (o1 == null || o1.getClass() != this.getClass()) {
  309. // return false;
  310. // }
  311. // Pair o = (Pair) o1;
  312. // if (o.x == this.x && o.y == this.y) {
  313. // return true;
  314. // }
  315. // return false;
  316. // }
  317. }
  318. class Sorting implements Comparator<Pair> {
  319. public int compare(Pair p1, Pair p2) {
  320. // if(p1.y==p2.y){
  321. // return Long.compare(p1.x,p2.x);
  322. // }else {
  323. return Long.compare(p1.x, p2.x);
  324. // }
  325. }
  326. }
  327. class Edge{
  328. int s=0;
  329. int d=0;
  330. int c=0;
  331. public Edge(int s,int d,int c){
  332. this.s=s;
  333. this.d=d;
  334. this.c=c;
  335. }
  336. }
Success #stdin #stdout 0.11s 51512KB
stdin
Standard input is empty
stdout
Standard output is empty