Advertisement
daskalot

Untitled

Apr 16th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.util.*;
  2. public class Izziv7{
  3. static int N;
  4. static boolean isPrime(int n){
  5. if (n==1) return false;
  6. if (n==2) return true;
  7. for (int i=2;i*i<=n;++i) if (n%i==0) return false;
  8. return true;
  9. }
  10. static void read(){
  11. Scanner sc = new Scanner(System.in);
  12. N = sc.nextInt();
  13. sc.close();
  14. }
  15. static int firstRoot;
  16. static String result = "";
  17. static boolean hasPrimiteRoot(int p){
  18. firstRoot = -1;
  19. result = "";
  20. boolean isPrinted = false;
  21. for(int i=2;i<p;i++){
  22. if(Math.pow(i,N)%p == 1){
  23. boolean isPrimitve = true;
  24. for(int j=1;j<N && isPrimitve;j++)
  25. isPrimitve = Math.pow(i,j)%p!=1;
  26. if(isPrimitve){
  27. if(!isPrinted){
  28. firstRoot = i;
  29. isPrinted = true;
  30. result = String.valueOf(p)+": ";
  31. }
  32. result+= String.valueOf(i) + " ";
  33. }
  34. }
  35. }
  36. return isPrinted;
  37. }
  38. static void solve(){
  39. int p = N;
  40. while(isPrime(p++) && hasPrimiteRoot(p));
  41. System.out.printf("%s\n",result);
  42. for(int k=0;k<N;System.out.printf("\n"),k++)
  43. for(int j=0;j<N;System.out.printf("%2d ",((long)Math.pow(Math.pow(firstRoot,k)%p,j))%p),j++);
  44. }
  45. public static void main(String[] args) {
  46. read();
  47. solve();
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement