#include #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; class linear_sieve{ vector lpf,p; public: linear_sieve(int n):lpf(n+1){ for(int i=2;i<=n;i++){ if(lpf[i]==0){ lpf[i]=i; p.emplace_back(i); } for(int j=0;j& primes()const{ return p; } bool is_prime(int a)const{ assert(a<=(int)lpf.size()-1); return a>0 && lpf[a]==a; } map prime_factorize(int a)const{ assert(a<=(int)lpf.size()-1); map pf; for(;a>1;a/=lpf[a]) ++pf[lpf[a]]; return pf; } int number_of_divisors(int a)const{ assert(a<=(int)lpf.size()-1); int res=1,cnt=0,pre=-1; for(;a>1;a/=lpf[a]){ if(pre==-1 || pre==lpf[a]){ cnt++; } else{ res*=cnt+1; cnt=1; } pre=lpf[a]; } return res*(cnt+1); } }; template vector divisors(const map& pf){ vector res={T(1)}; for(const auto& q:pf){ int m=res.size(); T pp=1; rep(i,q.second){ pp*=q.first; rep(i,m) res.emplace_back(res[i]*pp); } } sort(res.begin(),res.end()); return res; } int phi[1000001]; void build_phi(){ rep(i,1000001) phi[i]=i; for(int i=2;i<=1000000;i++) if(phi[i]==i) { for(int j=i;j<=1000000;j+=i) phi[j]=phi[j]/i*(i-1); } } int main(){ build_phi(); int n,m; scanf("%d%d",&n,&m); vector a(m); rep(i,m) scanf("%d",&a[i]); lint ans=0; linear_sieve LS(1e6); rep(i,m){ for(int d:divisors(LS.prime_factorize(a[i]))){ ans+=lint((a[i]-1)%d)*phi[a[i]/d]; } } printf("%lld\n",ans); return 0; }