Skip to content

Instantly share code, notes, and snippets.

@joriki
Created March 8, 2013 09:45
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 joriki/5115369 to your computer and use it in GitHub Desktop.
Save joriki/5115369 to your computer and use it in GitHub Desktop.
Count the number of solutions to a=-d, a^2+bc=1 mod 26; see http://math.stackexchange.com/questions/324542.
import java.util.Set;
import java.util.HashSet;
public class Question324542 {
final static int n = 26;
public static void main (String [] args) {
Set<Integer> residues = new HashSet<Integer> ();
for (int i = 0;i < n;i++)
residues.add ((i * i) % n);
int count = 0;
for (int b = 0;b < n;b++)
for (int c = 0;c < n;c++) {
int r = (1 - b * c + 26 * 26) % 26;
if (residues.contains (r))
count += r == 0 || r == 13 ? 1 : 2;
}
System.out.println (count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment