#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" usingnamespace std; #define MAXN 200006 int n , m; int A[MAXN] , B[MAXN];
intmain(){ int T;cin >> T; while( T-- ) { scanf("%d",&n); for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]); for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&B[i]); sort( A + 1 , A + 1 + n ) , sort( B + 1 , B + 1 + n ); for( int i = 1; i <= n ; ++ i ) printf("%d ",A[i]); puts(""); for( int i = 1; i <= n ; ++ i ) printf("%d ",B[i]); puts(""); } }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"vector" #include"map" usingnamespace std; #define int long long #define MAXN 200006 int n , m; int A[MAXN]; int buc[1006]; inlinelonglongab( longlong a ){ return a > 0 ? a : -a; } signedmain(){ scanf("%d%d", &n, &m); if( n > 2000 ) returnputs("0") , 0; for (int i = 1; i <= n; i++) scanf("%d", &A[i]); int res = 1; for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) res = ab(A[i] - A[j]) * res % m; cout << res << endl; }
#include<iostream> #include"algorithm" #include"cstring" #include"cstdio" #include"vector" #include"map" usingnamespace std; #define MAXN 5006 int n , m; int A[MAXN]; vector<int> ans; intmain(){ cin >> n >> m ; int c = 0 , r = 0; for( int i = 1 ; i <= n ; ++ i ) { if( ( i - 1 ) / 2 + c >= m ) { for( int j = i ; ; ++ j ) { if( ( ( i - 1 ) - ( j - i ) ) / 2 + c == m ) { for( int k : ans ) printf("%d ",k) , ++ r; printf("%d ",j) , ++ r; int t = 400000000; for( int i = r + 1 ; i <= n ; ++ i ) { printf("%d ",t) , t += 10000; } return0; } } } else { c += ( i - 1 ) / 2; ans.push_back( i ); } } puts("-1"); }
#include<iostream> #include<algorithm> #include<cstring> #include<string> #include<vector> #include<queue> #include"random" #include"chrono" usingnamespace std; #define MAXN 200006 #define int long long int n; int A[MAXN]; mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
intrnd( ){ returnrand(); } vector<int> divs; voidanalyze( int x ){ if( x < 2 ) return; int c = x; for( int i = 2 ; i * i <= x ; ++ i ) if( c % i == 0 ) { while( c % i == 0 ) c /= i; divs.push_back( i ); } if( c != 1 ) divs.push_back( c ); } int ans = 0x3f3f3f3f; voidchkans( int x ){ int re = 0; for( int i = 1 ; i <= n ; ++ i ) re += min( x - A[i] % x , A[i] >= x ? A[i] % x : 0x3f3f3f3f ); ans = min( ans , re ); }
signedmain(){ srand( Rnd( ) ); cin >> n; for( int i = 1 ; i <= n ; ++ i ) scanf("%lld",&A[i]); for( int t = 1 ; t <= 20 ; ++ t ) { for( int q = -3 ; q <= 3 ; ++ q ) analyze( A[rnd() % n + 1] + q ); } sort( divs.begin() , divs.end() ); divs.erase( unique( divs.begin() , divs.end() ) , divs.end() ); for( int i : divs ) chkans( i ); cout << ans << endl; }