Bob has an array P having N distinct elements from 0 to N-1. He makes another array D with the help of array P, such that for every Index T (151SN), DI-maximum of (P1, P2, P3 P For example: If the array P is [0, 3, 2, 4, 1], then array D will be [0, 3, 3, 4, 4] He gives this array D to Alice and asks her to generate the array P with the help of array D. He also gives her a hint that the array A is the lexicographically largest possible array she could make with the help of this array Help her to find the array P Please note: An array/list P is lexicographically smaller than its permutation Q if and only if, for the earliest index at which P and Qaffer P element at that Index is smaller than Q's element at that Index. Example, P = [1, 12, 4, 7, 8] is lexicographically smaller than Q-11, 12, 8:47 Constraints: 1≤T≤5 1≤N≤10^5 0≤D_
Answers
Answer:
fruit kung ton TNT got u u u can just don't don't want a a little little more more
Answer:
Program is generated
Explanation:
The most important thing we need to focus here is gcd(d1+d2 , a[i]) = 1.
For this condition to be true, d1 and d2 should be coprimes.
So, we need to find the 2 coprime divisors of a[i] and to find this, the smallest prime factor and it's multiplicity plays a big role.
For eg:
Suppose, N = p1^k1 * p2^k2 * ..... * pn^kn
Here, pi = prime factor, ki = multiplicity of pi.
60 = 2^2 * 3^1 * 5^1
Smallest prime factor = p1 = 2
Multiplicity of smallest prime factor = 2
So, 2^2 = 4, is coprime with the other pi^ki, i.e., 3^1 and 5^1.
Also, 2^2 = 4 is coprime with (3^1 * 5^1)
This is because, p1^k1 is corprime with (p2^k2 * p3^k3 * ...... * pn^kn).
So, Final Answer:
d1 = p1^k1
d2 = (p2^k2 * p3^k3 * ...... * pn^kn) = a[i]/d1
Program:
#include <iostream>
#include <vector>
#include <cmath>
#define maxn 1e7+10
int smallestPrime[(int)maxn];
std::vector<int> primes;
void primeFactorization(){
primes.push_back(2);
smallestPrime[0] = smallestPrime[1] = 1;
for ( int i = 2 ; i < maxn ; i += 2 )
smallestPrime[i] = 2;
for ( int i = 3 ; i < maxn ; i += 2 ) {
if ( smallestPrime[i] == 0 ){
smallestPrime[i] = i;
primes.push_back(i);
for ( int j = i ; j*(long long)i < maxn ; j += 2 ) {
if(smallestPrime[ i*j ] == 0)
smallestPrime[ i*j ] = i;
} } } }
int main(){
primeFactorization();
int n;
std::cin>>n;
int arr[1000000];
for(int i=0;i<n;i++){
std::cin>>arr[i];
}
int d1[1000000];
int d2[1000000];
for(int i=0;i<n;i++){
int tmp = arr[i];
int p1 = smallestPrime[tmp];
int k1 = 0;
while(tmp > 1 && p1 == smallestPrime[tmp])
tmp /= smallestPrime[tmp],++k1;
d1[i] = pow(p1, k1);
d2[i] = arr[i]/d1[i];
if(d1[i]==1 || d2[i]==1){
d1[i]=-1;d2[i]=-1;
}
}
for(int i=0;i<n;i++){
std::cout<<d1[i]<<" ";
}
std::cout<<std::endl;
for(int i=0;i<n;i++){
std::cout<<d2[i]<<" ";
}
return 0;}