Codeforces Round 868 (Div. 2) 1823C. Strongly Composite Solution
Problem Link : https://codeforces.com/problemset/problem/1823/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- map<int,int>mp ;
- for ( int k = 0 ; k < n ; k++){
- int x ;
- cin >> x ;
- for ( int i = 2 ; i * i <= x ; i++){
- if (x % i == 0){
- while ( x % i == 0){
- x /= i ;
- mp[i]++;
- }
- }
- }
- if ( x > 1 ){
- mp[x]++ ;
- }
- }
- int ans = 0 , cnt = 0 ;
- for ( auto i : mp){
- ans += (i.second / 2) ;
- cnt += (i.second % 2) ;
- }
- ans += (cnt / 3) ;
- cout << ans <<'\n' ;
- }
- return 0 ;
- }
No comments