Help Needed - Edit: Solved

Finding divisors of an integer is common task. We all did it in some time or other during our programming courses. We know that there are several ways to find divisors of an integer N. All of them involve some kind of programming using loops. But what if we ask you to solve the reverse problem?

Given all the proper (all the divisors except 1 and N) positive divisors of a positive composite integer N, you need to find the value of N.

Output format is here: Screenshot by Lightshot

Why do i get wrong answer please anyone help me…

using namespace std;
int main()
int t,Case=1;
int k,x,y,z;
long long int N;
while(k==2 ? cin>>x>>y : cin>>z)
N = z into z;
N = x into y;

    cout<<"Case "<< Case <<": "<< N<<'\n';

return 0;


What is this doing? :roll_eyes:

K > 0

It is mentioned in the problem statement.
And, your approach is not correct.

Here is the same problem.

Yeah! Already i’ve seen that.

I think the answer will be the LCM of the input numbers. If the LCM is a part of the input, multiply it by the lowest prime in the input.

1 Like

Or simply, it’s the product of smallest and largest elements in the given list of Divisors.

It will not work for, say, {2,5,7}

Nope, your input is invalid.
As said by @ssjgz in the above shared discussion, 2 5 7 is invalid input.

You are missing few divisors.

It should have been

2 5 7 10 14 35


2 Doesn’t divide 35 :upside_down_face:

This post was flagged by the community and is temporarily hidden.

Woah, what’s wrong?

Does the question specify that it will give repetitive divisors also, like for example for numbers 4,9,25 which have only one unique divisor,this set will contain all the squares of prime numbers.
If it does not then you would have to handle them separately.

I knew my post was wrong. Before I could edit that post, you had to comment with that stupid emoji of yours. That’s what’s wrong.

Ok I deleted that. Give me a proof that product of smallest and largest numbers gives the answer.

It’s easy.

Consider a Positive Composite Integer N. Surely, N can be split into two factors, say, (a) and (N/a). Let a be the smallest factor of N, then (N/a) will be the largest factor of N.

It was mentioned in the question that all factors will be listed. So, definitely, a and N/a will be present in the list. Find the smallest and largest in the given list. These are indeed a and (N/a) respectively.

Their product gives the answer. (a \times (N/a) = N)

It can easily be understood by taking the prime factorization of a composite number.
Leave the smallest prime factor and take product of other prime factors that is bound to be the largest factor and the total product is the original number.

Very little information was provided. We don’t have a link to the actual problem. And I think it doesn’t matter whatever way they give the input when our approach is to find min and max of the list.

Say For N = 25.
Type 1:




// Because max and min of the list are 5 and 5 respectively.

Type 2:


5 5


// Max and min are again 5 and 5 respectively.

Yeah the Question is not clear, but as long as the question makes sure that all the proper divisors are given it is fine also for single divisor as both max and min will be at same array index.

1 Like