# Need Help on a problem

Some crazy white old man, calling himself the “Danger”, after watching a certain T.V series planned to research and invent his own “chemical”. After finishing his recipe, he found out he needs exactly n grams of the main ingredient to make it. If he makes with less than n grams, the mixture is not reactive enough and if he makes it with more than n grams, it simply explodes. He browsed Ebay and found only 2 sellers for the item. Seller A only sells n1 gram containers for c1 rupees each. Seller B only sells n2 gram containers for c2 rupees each. If it’s possible to buy exactly n grams from these 2 sellers, output the minimum cost of buying the ingredients

I tried using linear diaphontine equations, but the solution fails for large inputs.

Can someone help me solving this problem?

I found one of the solutions and tried to make the both values positive.

@ssjgz

did u solve Thala and Factor Array ? if yes then please tell @prad8109

Here is the solution to the problem…

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int n;
cin>>n;
int count[(int)1e6 + 5]{0};
for(int i = 0; i < n; i++) {
int x; cin>>x;
cout<<count[x]<<"\n";
for(int j = 1; j <= sqrt(x); ++j) {
if(x % j == 0) {
count[j]++;
if(j * j != x)
count[x / j]++;
}
}
}
return 0;
}``````

Thanks bro already did same question in OCT long MSV

1 Like