Skip to content

Instantly share code, notes, and snippets.

@kuuso
Created January 14, 2016 14:36
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 kuuso/2aed68cc024b9aec33c0 to your computer and use it in GitHub Desktop.
Save kuuso/2aed68cc024b9aec33c0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
// (x+y)(x-y)=(B-A)(B+A)=Z として、Zの約数から(x、y)が解けるものを選ぶ
long Z=(B-A)*(B+A);
long ans=0;
for(long i=1;i*i<=Z;i++){
if(Z%i!=0)continue;
if(i*i==Z)continue;// case: (X+Y)==(X-Y) => Y==0 is not Natural Number;
if((i+Z/i)%2==0)ans+=Z/i;
}
Console.WriteLine(ans);
}
long A,B;
public Sol(){
var d=rla();
A=d[0];B=d[1];
}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment