Advertisement
Guest User

Lampochki

a guest
Oct 27th, 2012
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. uses math;
  2. var
  3. q:array[0..100001,0..3] of longint;
  4. a,b:array[0..500010] of longint;
  5. x,y,yy,i,j,z,t,q1,q2:longint;
  6. st,stt:array[0..50100] of string;
  7. p:array[1..50000] of boolean;
  8. s,ss,sw:string;
  9. // x,y,xx,yy:extended;
  10. c:char;
  11. w:array['a'..'z'] of longint;
  12. xx,n,m,k,ans,tp:int64;
  13.  
  14.  
  15. function nok(a,b:int64):int64;
  16. var
  17. i,j:int64;
  18. begin
  19. i:=a;j:=b;
  20. while i*j<>0 do
  21. if i>j then i:=i mod j else j:=j mod i;
  22. nok:=(a*b) div (i+j);
  23.  
  24. end;
  25.  
  26. begin
  27. assign(input,'input.txt');reset(input);
  28. assign(output,'output.txt');rewrite(output);
  29. read(n,m);
  30. for i:=1 to m do read(a[i]);
  31. z:=0;
  32. for i:=1 to m do
  33. begin
  34. for j:=1 to z do
  35. begin
  36. tp:=nok(q[j,1],a[i]);
  37. if tp<=n then begin
  38. inc(z);
  39. q[z,1]:=tp;q[z,2]:=q[j,2]*(-2);
  40. end;
  41.  
  42. end;
  43. inc(z);
  44. q[z,1]:=a[i];q[z,2]:=1;
  45. end;
  46. ans:=0;
  47. for i:=1 to z do
  48. begin
  49. ans:=ans+(n div q[i,1])*q[i,2];
  50. end;
  51. write(ans);
  52. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement