int qpow(int a,int b,int mod){
int ret=1;
while(b>0){
if(b&1) ret=ret*a%mod;
a=a*a%mod;
b>>=1;
}
return ret;
}bool isprime(int x){
if(x==1) return false;
for(int i=2;i<=sqrt(x);i++){
if(x%i==0) return false;
}
return true;
}bool prime[N];
bool build(int n){
fill(prime+2,prime+N,true);
for(int i=2;i<N;i++){
if(prime[i]){
for(int j=i+i;j<N;j+=i) prime[j]=false;
}
}
}#include<bits/stdc++.h>
#define int long long
#define mp make_pair
#define eb emplace_back
#define rep(n) for(int i=0;i<n;i++)
#define rep2(n) for(int j=0;j<n;j++)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define Woody
#ifdef Woody
#define quick ios::sync_with_stdio(0);cin.tie(0);
#else
#define quick
#endif
const int INF=1e18;
const int N=1e6+7;
using namespace std;
int cnt[N];
signed main(){
quick
fill(cnt,cnt+N,0);
int n;
cin>>n;
rep(n){
int x;
cin>>x;
cnt[x]++;
}
for(int i=N-1;i>=1;i--){
int ans=0;
for(int j=i;j<N;j+=i){
ans+=cnt[j];
}
if(ans>1) {
cout<<i<<"\n";
return 0;
}
}
#pragma GCC optimzize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=1e6+7;
const int INF=1e18;
int x[N];
int sum[N];
int ans[N];
signed main(){
quick
int n;
cin>>n;
rep(i,1,n) cin>>x[i],sum[x[i]]++;
rep(i,2,N-1){
int cnt=sum[i];
for(int j=i+i;j<N;j+=i){
if(sum[j]) cnt+=sum[j];
}
ans[i]=cnt*(cnt-1)/2;
}
int S=0;
repd(i,N-1,2){
for(int j=i+i;j<N;j+=i) ans[i]-=ans[j];
S+=ans[i];
}
cout<<n*(n-1)/2-S<<"\n";
return 0;
int gcd(int a, int b){
while(b > 0){
int t = a % b;
a = b;
b = t;
}
return a;
}
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}pair<int,int> exgcd(int a,int b){
if(b==0) return mp(1,0);
pii res=exgcd(b,a%b);
return res.S,res.F-a/b*res.S;
}int inv(int x,int Mod){
return qpow(x,Mod-2,Mod)
}#include<bits/stdc++.h>
//#define Woody
#define int long long
#define lowbit(x) (x&-x)
#define max3(a,b,c) max(max(a,b),c)
#define rep(n) for(int i=0;i<n;i++)
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define all(v) v.begin(),v.end()
#define SETIO(s) ifstream cin(s+".in");ofstream cout(s+".out");
#ifdef Woody
#define quick ios::sync_with_stdio(0);cin.tie(0);
#else
#define quick
#endif
#define INF 1e12
using namespace std;
typedef pair<int,int> pii;
const int N=101;
const int Mod=1e9+7;
int l[2][N][N]={0};
struct matrix{
vector<vector<int >> v;
int n;
void init(int x,int pos)
{
n=x;
v.assign(n,vector<int>(n,0));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
v[i][j]=l[pos][i][j];
}
}
}
void multiply(matrix &k){
vector<vector<int> > v2;
v2.assign(n,vector<int>(n,0));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int m=0;m<n;m++){
v2[i][j]+=v[i][m]*k.v[m][j];
v2[i][j]%=Mod;
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
v[i][j]=v2[i][j];
}
}
}
}st,ans;
signed main(){
quick
int n,m,k;
cin>>n>>m>>k;
//fill_n(l[0],2*N*N,0);
while(m--){
int a,b;
cin>>a>>b;
l[0][--a][--b]++;
}
for(int i=0;i<n;i++){
l[1][i][i]=1;
}
st.init(n,0);
ans.init(n,1);
while(k>0){
if(k&1){
ans.multiply(st);
}
st.multiply(st);
k>>=1;
}
cout<<ans.v[0][n-1]<<"\n";
}
#pragma GCC optimzize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=1e3+7;
const int INF=1e18;
vector<int> v[N];
int M;
int qpow(int a,int b){
int ret=1;
while(b>0){
if(b&1) ret=ret*a%M;
a=a*a%M;
b>>=1;
}
return ret;
}
int inv(int x){
return qpow(x,M-2);
}
signed main(){
quick
int n;
cin>>n>>M;
vector<int> st(n);
rep(i,0,n-1) cin>>st[i];
rep(i,0,n-1){
rep(j,0,n-1){
int x;
cin>>x;
v[j].eb(x);
}
}
rep(i,0,n-1){
v[i].eb(st[i]);
}
rep(i,0,n-1){
if(!v[i][i]){
rep(j,i+1,n-1){
if(v[j][i]){
swap(v[j],v[i]);
break;
}
}
}
rep(j,i+1,n-1){
int mul=(M-v[j][i]%M*inv(v[i][i])%M)%M;
rep(x,i,n){
v[j][x]=(v[j][x]+mul*v[i][x])%M;
}
}
}
vector<int> ans(n);
repd(i,n-1,0){
int s=v[i][n];
rep(j,i+1,n-1){
s=s-v[i][j]*ans[j]%M;
s=(s+M)%M;
}
ans[i]=s*inv(v[i][i])%M;
}
rep(i,0,n-1){
cout<<ans[i]<<" \n"[i==n-1];
}
return 0;
}
有一個 \(8\times 8\) 的方格,一開始每個格子上都有一台機器人,每次機器人會在不超出邊界的情況下從上下左右中可走的方向隨機選一個並移動,每個被選到的機率相同。求在 \(k\) 次移動後空格數量的期望值為多少。
\(k≤100\)
給定 求 \(1 \sim n\) 中有幾個數至少有幾個為陣列 \(a\) 中任一數的倍數。 \(a\) 陣列長度為 \(k\)
\(1≤n≤10^{18} \\ 1≤k≤20 \\ 2≤a≤10^5\)