QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735675 | #8980. Prime Game | Wzy | WA | 23ms | 11756kb | C++14 | 1.8kb | 2024-11-11 21:14:07 | 2024-11-11 21:14:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<char,int> PCI;
typedef pair<int,int> PII;
const int N=1000010,M=2000010;
const int mod=1e9+7;
int INF = 1e9;
int T=1;
int phi[N],st[N],primes[N],cnt,f[N];
void init(int n)
{
phi[1] = 1;
for (int i = 2; i <= n; i ++ )
{
if (!st[i])
{
primes[cnt ++ ] = i;
phi[i] = i - 1;
}
for (int j = 0; primes[j] * i <= n; j ++ )
{
st[i * primes[j]] = true;
if (i % primes[j] == 0)
{
phi[i * primes[j]] = phi[i] * primes[j];
break;
}
phi[i * primes[j]] = phi[i] * (primes[j] - 1);
}
}
}
void solve(){
int n;
cin>>n;
vector<int> a(n+10);
for(int i=0;i<n;i++) cin>>a[i];
map<int,vector<int>> mp;
map<int,int> id;
for(int i=0;i<n;i++) id[a[i]]=i;
for(int i=0;i<cnt;i++){
for(int j=primes[i];j<=N-1;j+=primes[i]){
if(!id.count(j)) continue;
//cout<<j<<" "<<primes[i]<<" "<<id[j]<<endl;
mp[primes[i]].push_back(id[j]);
}
}
LL res=0;
for(auto [x,y]:mp){
sort(y.begin(),y.end());
//cout<<x<<endl;
//for(auto t:y) cout<<t<<" ";
//cout<<endl;
for(int i=0;i<y.size();i++){
//cout<<x<<" "<<y[i]<<endl;
if(i==y.size()-1) res+=(n-y[i])*(y[i]+1);
else res+=(y[i+1]-y[i])*(y[i]+1);
}
}
cout<<res<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//int T=1;
//cin>>T;
init(N-1);
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 16ms
memory: 11756kb
input:
10 99 62 10 47 53 9 83 33 15 24
output:
248
result:
ok single line: '248'
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 11752kb
input:
10 6 7 5 5 4 9 9 1 8 12
output:
126
result:
wrong answer 1st lines differ - expected: '134', found: '126'