QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#288152 | #7749. A Simple MST Problem | UNos_maricones# | RE | 7ms | 9504kb | C++17 | 1.7kb | 2023-12-22 06:13:44 | 2023-12-22 06:13:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 100'100;
const int INF = (int) 1e9;
bool cmp[N];
int rn[N];
vector< int > primes[N];
int solve()
{
int l, r;
cin >> l >> r;
const int n = ( r - l + 1 );
vector< int > v;
for( int i = l; i <= r; ++ i )
{
v.push_back( rn[i] );
//cout << i << " " << rn[i] << " " << primes[i].size() << endl;
}
sort( v.begin(), v.end(), [&]( int x, int y ){
if( primes[x].size() != primes[y].size() )
return primes[x].size() < primes[y].size();
return x < y;
});
vector< int > mn_cost_mul( r + 1, INF );
int ans = 0;
for( int i = 0; i < n; ++ i )
{
const int x = v[i];
const int wx = (int) primes[x].size();
int mn_cost = INF;
for( int mask = 0; mask < ( 1 << wx ); ++ mask )
{
int div = 1, wdiv = 0;
for( int j = 0; j < wx; ++ j )
if( mask >> j & 1 )
div *= primes[x][j], ++wdiv;
mn_cost = min( mn_cost, mn_cost_mul[div] );
mn_cost_mul[div] = min( mn_cost_mul[div], wx - wdiv );
}
mn_cost += wx;
if( i != 0 ) ans += mn_cost;
}
return ans;
}
int main()
{
cin.tie( NULL );
ios_base::sync_with_stdio( 0 );
iota( rn, rn + N, 0 );
for( int i = 2; i < N; ++ i )
{
if( !cmp[i] )
{
long long i2 = 1LL * i * i;
for( int j = i; j < N; j += i )
{
cmp[j] = true;
if( j % i2 == 0 )
rn[j] = j/i;
primes[j].push_back( i );
}
}
if( rn[i] != i )
rn[i] = rn[rn[i]];
}
int t;
cin >> t;
while( t-- )
cout << solve() << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 9504kb
input:
5 1 1 4 5 1 4 1 9 19 810
output:
0 2 3 9 1812
result:
ok 5 lines
Test #2:
score: -100
Runtime Error
input:
2 27 30 183704 252609