fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5.  
  6. public class Main {
  7.  
  8. public static void main (String args []) throws Exception{
  9.  
  10. int m = Integer.parseInt(reader.readLine());
  11.  
  12. for(String line = reader.readLine(); line != null; line = reader.readLine()){
  13. int n = Integer.parseInt(line);
  14. int fibn = (int) ((int)((1/Math.sqrt(5))* (Math.pow((1 + Math.sqrt(5))/2, n) - Math.pow((1 - Math.sqrt(5))/2, n)))% m);
  15. System.out.println(fibn);
  16. }
  17.  
  18. }
  19. }
  20.  
  21.  
  22.  
Success #stdin #stdout 0.02s 245632KB
stdin
1000
99995
99996
99997
99998
99999
100000
10000000
stdout
647
647
647
647
647
647
647