Advertisement
Rentib

zad 10

Jan 2nd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int nwd(int a, int b){
  4. return b ? nwd(b, a % b) : a;
  5. }
  6. int main(){
  7. int n, k = 0;
  8. cin >> n;
  9. if(n > 4 && n % 2 == 1)
  10. k = 2;
  11. for(int i = 2;i < n / 2 && !k;i++)
  12. if(nwd(i, n) == 1)
  13. k = i;
  14. if(k == 0){
  15. cout << "NIE DA SIE STWORZYC MAGICZNEGO KWADRATU O BOKU " << n;
  16. return 0;
  17. }
  18. for(int i = 0;i < n;i++){
  19. for(int j = 1;j <= n;j++)
  20. cout << ((i * k + j) % n == 0 ? n : (i * k + j) % n) << ' ';
  21. cout << '\n';
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement