Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created June 11, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/12a27ecf9a0968db72c268653774b45d to your computer and use it in GitHub Desktop.
Save jianminchen/12a27ecf9a0968db72c268653774b45d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static int countSolutions(int a, int b, int c, int d)
{
int count = 0;
// Complete this function
for (int x = 1; x <= c; x++)
{
var leftBase = x * x;
var rightBase = x * a;
var difference = leftBase - rightBase;
// it is not sorted and binary search not working
for(int y = 1; y <= d; y++)
{
var leftPart = y * y;
var rightPart = y * b;
var differenceII = leftPart - rightPart;
var sum = difference + differenceII;
if (sum == 0)
{
count++;
}
}
}
return count;
}
static void Main(String[] args)
{
int q = Convert.ToInt32(Console.ReadLine());
for (int a0 = 0; a0 < q; a0++)
{
string[] tokens_a = Console.ReadLine().Split(' ');
int a = Convert.ToInt32(tokens_a[0]);
int b = Convert.ToInt32(tokens_a[1]);
int c = Convert.ToInt32(tokens_a[2]);
int d = Convert.ToInt32(tokens_a[3]);
int result = countSolutions(a, b, c, d);
Console.WriteLine(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment