A-找一找_Wannafly挑战赛9 (nowcoder.com)
题意:
思路:
注意细节
ai=1时特判
枚举时最好枚举 i
Code:
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int mxn=1e6+10;
const int mxe=1e5+10;
const int mod=1e9+7;
const int Inf=0x3f3f3f3f;
int N;
int a[mxn],mp[mxn];
void solve(){
cin>>N;
for(int i=1;i<=N;i++){
cin>>a[i];
mp[a[i]]++;
}
int ans=0;
for(int i=1;i<=N;i++){
if(a[i]==1){
ans++;
continue;
}
for(int j=a[i]*2;j<=1e6;j+=a[i]){
if(mp[j]!=0){
ans++;
break;
}
}
}
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int __=1;//cin>>__;
while(__--)solve();return 0;
}