304 North Cardinal St.
Dorchester Center, MA 02124

# Equation Solver CodeChef Solution

## Equation Solver CodeChef Solution in C++14

``````#include <cstdio>
#include <vector>
using namespace std;

vector<int> Divisors(int n) {
int i = 1;
for (; i < n / i; ++i) {
if (n % i == 0) {
}
}
if (i == n / i && n % i == 0) {
}
}

int DistinctFactors(int n) {
for (int i = 2; i <= n / i; ++i) {
bool visited = false;
while (n % i == 0) {
n /= i;
visited = true;
}
}
}

struct Solution {
int A, B, C;

void Solve() {
scanf("%d%d%d", &A, &B, &C);
printf("%d\n", Compute());
}

int Compute() {
if (A > 0) {
for (int d : Divisors(A)) {
int x0 = A / d + C;
int x1 = d - B;
if (x1 == 0) {
if (x0 == 0) return -1;
continue;
}
if (x0 % x1 != 0) continue;
int t = x0 / x1;
if (0 < t) answer += 1 << DistinctFactors(t);
}
} else if (C > 0) {
for (int e : Divisors(C)) {
int t = C / e;
if (0 < t) answer += 1 << DistinctFactors(t);
}
} else if (B > 0) {
return -1;
}
}
};

int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; ++i) Solution().Solve();
return 0;
}``````

## Equation Solver CodeChef Solution in C

``````#include <stdio.h>

int count(int n) {
int ans = 1, i;
for (i=2;i*i<=n;i++)
if (n % i == 0) {
ans *= 2;
while (n % i == 0) n /= i;
}
if (n > 1) ans *= 2;
return ans;
}

int main() {
int t,a,b,c,d,ans;
scanf("%d",&t);
while (t--) {
scanf("%d %d %d",&a,&b,&c);
if (a == 0 && c == 0) {
printf("%d\n",b ? -1 : 0);
continue;
}
ans = 0;
for (d=b+1;a/d+c >= d-b;d++)
if (a % d == 0 && (a/d+c) % (d-b) == 0) ans += count((a/d+c)/(d-b));
printf("%d\n",ans);
}
return 0;
}``````

## Equation Solver CodeChef Solution in JAVA

``````import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class Main {

public static int countCalc(int n){
int result = 1;
for(int i = 2; i*i < n; i++){
if( n % i == 0){
result*=2;
while(n%i == 0)
n/=i;
}
}
if(n>1)
result*=2;
return result;
}
public static void main(String[] args) throws IOException {
// Input from File

// Input from Standard Input Stream
while(tests-- > 0){
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
int c = Integer.parseInt(input[2]);
if(a==0 && c==0){
if(b==0) System.out.println("0");
else System.out.println("-1");
}else{
int count = 0;
for(int d=(b+1);(a/d + c)>= (d-b);d++){
if(a % d == 0 && ((a/d + c) % (d-b)== 0))
count+=countCalc((a/d+c)/(d-b));

}
System.out.println(count);
}
}

}
}``````

## Equation Solver CodeChef Solution in PYTH

``````from math import sqrt

def fn():
a,b,c = map(int,raw_input().split())
if a == 0 and b > 0 and c==0:
print -1
return
af,cf = [], []
for i in range(1,int(sqrt(a))+1):
if i*i == a:
af.append(i)
else:
if a%i==0:
af.append(i)
af.append(a/i)

for i in range(1,int(sqrt(c))+1):
if i*i == c:
cf.append(i)
else:
if c%i==0:
cf.append(i)
cf.append(c/i)

xy = []
for g in af:
if g*g - b*g>0:
if (g*c+a)%(g*g-b*g)==0:
xy.append((g*c+a)/(g*g-b*g))
elif g*g - b*g == 0:
if a == 0 and c ==0:
print -1
return
if a==0:
for x in cf:
xy.append(c/x)

np = []
for i in xy:
cnt = 0
for j in range(2,int(sqrt(i)+1)):
if i%j == 0:
cnt += 1
while(i%j==0):
i/=j
if i != 1:
cnt += 1
np.append(cnt)

sm = 0
for i in np:
sm+=pow(2,i)

print sm

t = int(raw_input())
for i in range(t):
fn()  ``````
##### Equation Solver CodeChef Solution Review:

In our experience, we suggest you solve this Equation Solver CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Equation Solver CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Equation Solver CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!