QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321780 | #4584. Not One | owen0806# | WA | 147ms | 112372kb | C++20 | 1.8kb | 2024-02-05 15:33:43 | 2024-02-05 15:33:44 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define PB push_back
#define pii pair<int, int>
using namespace std;
const int N = 2e6 + 5;
const int INF = 1e18;
vector<int> prime;
bool isprime[N];
void init(){
for(int i=2; i<=1e6; i++) isprime[i] = 1;
for(int i=2; i<=1e6; i++){
if(!isprime[i]) continue;
prime.PB(i);
for(int j=i*i; j<=1e6; j+=i){
isprime[j] = 0;
}
}
}
int a[N], vis[N];
map<int, vector<int>> edge[N];
set<int> st;
int dfs(int x, int f, int pr){
vis[x] = 1;
for(auto i : edge[x][pr]){
if(i == f || vis[i]) continue;
vis[x] += dfs(i, x, pr);
}
return vis[x];
}
void solve(){
init();
int n;
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=0; i<n-1; i++){
int aa, bb;
cin >> aa >> bb;
int g = gcd(a[aa], a[bb]);
int x = g;
for(int j=2; j*j<=g; j++){
if(x % j == 0){
st.insert(j);
edge[aa][j].PB(bb);
edge[bb][j].PB(aa);
while(x % j == 0)
x /= j;
}
}
if(x > 1){
edge[aa][x].PB(bb);
edge[bb][x].PB(aa);
}
}
int ans = 0;
for(auto pr : st){
for(int i=1; i<=n; i++){
// for(auto j : edge[i][pr]) cout << j << " ";
// cout << endl;
if(a[i] % pr) continue;
if(vis[i]) continue;
ans = max(ans, dfs(i, i, pr));
}
for(int i=1; i<=n; i++)
vis[i] = 0;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while(T--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 17ms
memory: 98792kb
input:
7 10 5 8 6 10 6 4 1 2 2 3 2 4 4 5 4 6 4 7
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 15ms
memory: 98800kb
input:
4 1 1 1 1 1 2 2 3 3 4
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 19ms
memory: 98884kb
input:
5 100 100 100 100 100 3 4 1 2 3 5 2 4
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Accepted
time: 27ms
memory: 98924kb
input:
2 1 1 1 2
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 140ms
memory: 112372kb
input:
100000 860163 795323 862289 543383 792647 337047 353985 959953 874318 573652 69827 958063 571741 704399 311826 920477 792478 151531 872269 592307 853819 865817 940735 620657 937154 696551 749279 552523 836161 707467 389626 459089 563763 668884 810391 639709 419361 580342 519595 836124 494959 669379 ...
output:
213
result:
ok single line: '213'
Test #6:
score: -100
Wrong Answer
time: 147ms
memory: 104724kb
input:
100000 999983 999983 999961 999961 999979 999979 999979 999961 999983 999961 999979 999961 999961 999983 999961 999983 999983 999979 999961 999979 999983 999979 999983 999961 999979 999961 999979 999979 999961 999979 999983 999979 999961 999961 999961 999961 999961 999983 999979 999983 999979 999961...
output:
0
result:
wrong answer 1st lines differ - expected: '70', found: '0'