Language: C++

#include <bits/stdc++.h>

using namespace std;

const int N = 505 ;
const int M = 10000;

int noLin , noPrimes ;
vector < int > allPrimes ;
int isPrime[ M ] ;
int diagPrin [ N ] , diagSec[ N ];

__int128 mat [ N ][ N ];

void genCiur(){
    int i ;

    for ( i = 2 ; i * i < M ; i++ ){

        if ( isPrime [ i ] == 0 ){
            allPrimes.push_back( i );
        }

        for ( int j = i*i ; j < M ; j+=i ){
            isPrime [ j ] = 1 ;
        }
    }
    for ( ;i < M ; i++ ){
        if ( isPrime [ i ] == 0 ){
            allPrimes.push_back( i );
        }
    }

}


__int128 cmmdc ( __int128 a , __int128 b ){

    while ( b ){
        __int128 t = a % b ;
        a = b ;
        b = t ;
    }
    return a ;

}

__int128 calcLCM ( __int128 a , __int128 b ){

    return a * b / cmmdc ( a , b );

}

int main(){



    scanf("%d",&noLin);

    noPrimes = 2 * noLin  + 1 ;

    genCiur ();



    vector<int>::iterator it = allPrimes.begin();

    for ( int crLin = 0 ; crLin < noLin ; crLin +=2 ){
        int i = crLin ;
        for ( int j = 0 ; j < noLin && i < noLin ; i++ , j++  ){
            mat [ i ][ j ] = *it ;
        }
        it++;
    }

    for ( int crCol = 2 ; crCol < noLin ; crCol+=2 ){
        int j = crCol ;
        for ( int i = 0 ; j < noLin ; i++,j++ ){
            mat [ i ][ j ] = *it ;
        }
        it ++;
    }

    for ( int crCol = 0 ; crCol < noLin ; crCol+=2 ){
        int i = crCol ;
        for ( int j = 0 ; i >= 0 && j < noLin ; i-- , j++  ){
            mat [ i ][ j ] *= *it ;
        }
        it++;
    }

    for ( int crLin = noLin - 1 ; crLin >= 0 ; crLin-=2 ){
        int i = crLin ;
        for ( int j = noLin - 1 ; i < noLin ; i++ ,j-- ){
            mat [ i ][ j ] *= *it ;
        }
        it ++;
    }





    for ( int i = 0 ; i < noLin ; i++ ){
        for ( int j = 0 ; j < noLin ; j++ ){

            __int128  a = 1 , b = 1  ,c = 1 , d = 1 ;

            if ( mat [ i ][ j ] == 0 ){
                if ( i ) {
                    a = mat [ i - 1 ][ j ];
                }
                if ( j ){
                    b = mat [ i ][ j - 1 ];
                }
                if ( i < noLin - 1 ){
                    c = mat [ i + 1 ][ j ];
                }
                if ( j < noLin - 1 ){
                    d = mat [ i ][ j + 1 ];
                }
                a = calcLCM( a, b );
                a = calcLCM( a, c );
                a = calcLCM( a, d );
                mat [ i ][ j ] = a + 1 ;
            }


        }
    }

    for ( int i = 0 ; i < noLin ; i++ ){
        for ( int j = 0 ; j < noLin ; j++ ){
            cout << mat [ i ][ j ] << " " ;
            
        }
        printf("\n" );
    }



    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:134:18: error: ambiguous overload for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and '__int128')
  134 |             cout << mat [ i ][ j ] << " " ;
      |             ~~~~ ^~ ~~~~~~~~~~~~~~
      |             |                    |
      |             |                    __int128
      |             std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  174 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  178 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  182 |       operator<<(bool __n)
      |       ^~~~~~~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  189 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
  110 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  200 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  211 |       operator<<(long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  215 |       operator<<(unsigned long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  231 |       operator<<(double __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  235 |       operator<<(float __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  243 |       operator<<(long double __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char) [with _CharT = char; _Traits = char_traits<char>]'
  573 |     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char) [with _Traits = char_traits<char>]'
  579 |     operator<<(basic_ostream<char, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char) [with _Traits = char_traits<char>]'
  590 |     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char) [with _Traits = char_traits<char>]'
  595 |     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
      |     ^~~~~~~~