The_Law

Untitled

Sep 20th, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. enum
  5. {
  6.     MAX_N = 2000
  7. };
  8.  
  9. int
  10. prime(long long n)
  11. {
  12.     for (long long i = 2; i * i <= n; ++i) {
  13.         if (n % i == 0) {
  14.             return 0;
  15.         }
  16.     }
  17.     return 1;
  18. }
  19.  
  20. int
  21. main(void)
  22. {
  23.     int n;
  24.     scanf("%ld", &n);
  25.  
  26.     if (n < 1 || MAX_N < n || !prime(n)) {
  27.         exit(EXIT_FAILURE);
  28.     }
  29.  
  30.     int res[MAX_N];
  31.     res[1] = 1;
  32.  
  33.     for (int i = 0; i < n; ++i) {
  34.         for (int j = 1; j < n; ++j) {
  35.             res[j] = j > 1 ? (n - (n / j) * res[n % j] % n) % n : res[j];
  36.             printf("%d ", (res[j] * i) % n);
  37.         }
  38.         printf("\n");
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment