Created
March 8, 2013 09:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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