Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Factors problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Factors problem solution, Ben had two numbers M and N. He factorized both the numbers, that is, expressed M and N as a product of prime numbers.
                  M = (P1A1)*(P2A2 )*(P3A3)*… *(PNAN)
                  N = (Q1B1)*(Q2B2 )*(Q3B3)*… *(QNBN)
 
Here, * represents multiplication.
P1, P2 …PN  are distinct prime numbers. 
Q1, Q2 …QN are distinct prime numbers.
Unfortunately, Ben has lost both the numbers M and N but still he has arrays A and B. He wants to reterive the numbers M and N but he will not be able to. Your task is to determine the minimum and the maximum number of factors their product (that is, M * N) could have. Your task is to tell Ben the minimum and the maximum number of factors that the product of M and N could have.
Since the answer can be large, print modulo 1000000007.
 
 
HackerEarth Factors problem solution

 

 

HackerEarth Factors problem solution.

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define m 1000000007
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
FIO;
test
{
ll n,i,ans1=1,ans2=1;
cin>>n;
ll a[n],b[n];
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=0;i<n;i++){
cin>>b[i];
}
sort(a,a+n);
sort(b,b+n,greater<ll>());
for(i=0;i<n;i++){
ans1*=(a[i]+b[i]+1);
ans1%=m;
ans2*=(a[i]+1);
ans2%=m;
ans2*=(b[i]+1);
ans2%=m;
}
cout<<ans1<<" "<<ans2<<endl;
}
return 0;
}
 

Second solution

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e5 + 14, M = 1e9 + 7;
int n;

int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
int a[n], b[n];
int mx = 1;
for (int i = 0; i < n; ++i) {
cin >> a[i];
mx = (ll) mx * (a[i] + 1) % M;
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
mx = (ll) mx * (b[i] + 1) % M;
}
sort(a, a + n);
sort(b, b + n, greater<int>());
int mn = 1;
for (int i = 0; i < n; ++i)
mn = (ll) mn * (a[i] + b[i] + 1) % M;
cout << mn << ' ' << mx << 'n';
}
}
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes