Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Izziv7{
- static int N;
- static boolean isPrime(int n){
- if (n==1) return false;
- if (n==2) return true;
- for (int i=2;i*i<=n;++i) if (n%i==0) return false;
- return true;
- }
- static void read(){
- Scanner sc = new Scanner(System.in);
- N = sc.nextInt();
- sc.close();
- }
- static int firstRoot;
- static String result = "";
- static boolean hasPrimiteRoot(int p){
- firstRoot = -1;
- result = "";
- boolean isPrinted = false;
- for(int i=2;i<p;i++){
- if(Math.pow(i,N)%p == 1){
- boolean isPrimitve = true;
- for(int j=1;j<N && isPrimitve;j++)
- isPrimitve = Math.pow(i,j)%p!=1;
- if(isPrimitve){
- if(!isPrinted){
- firstRoot = i;
- isPrinted = true;
- result = String.valueOf(p)+": ";
- }
- result+= String.valueOf(i) + " ";
- }
- }
- }
- return isPrinted;
- }
- static void solve(){
- int p = N;
- while(isPrime(p++) && hasPrimiteRoot(p));
- System.out.printf("%s\n",result);
- for(int k=0;k<N;System.out.printf("\n"),k++)
- for(int j=0;j<N;System.out.printf("%2d ",((long)Math.pow(Math.pow(firstRoot,k)%p,j))%p),j++);
- }
- public static void main(String[] args) {
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement