Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef long double ld;
- typedef long long llint;
- const ld eps = 1e-9;
- const int deg = (1 << 17)+1;
- const int shift = 10001;
- struct comp {
- ld x, y;
- comp() { x = y = 0.0; }
- comp( ld X, ld Y ) { x = X; y = Y; }
- comp( ld phi ) { x = cos( phi ); y = sin( phi ); }
- };
- int N;
- comp p[ deg ]; int q[ deg ], r[ deg ];
- comp s[ deg ], c[ deg ];
- comp tmp[ deg ];
- inline comp operator+( comp a, comp b ) { return comp( a.x+b.x, a.y+b.y ); }
- inline comp operator-( comp a, comp b ) { return comp( a.x-b.x, a.y-b.y ); }
- inline comp operator*( comp a, comp b ) { return comp( a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x ); }
- void fft( comp *a, int x, int n, int t ) {
- if( n == 1 ) return;
- int h = ( n >> 1 );
- comp w( 1.0, 0.0 ), cw;
- comp W( t*2.0*M_PI/n );
- for( int i = 0; i < n; ++i ) tmp[i] = a[x+i];
- for( int i = 0; i < n; i += 2 ) a[x+(i>>1)] = tmp[i];
- for( int i = 1; i < n; i += 2 ) a[x+h+(i>>1)] = tmp[i];
- fft( a, x, h, t );
- fft( a, x+h, h, t );
- for( int i = 0; i < n; ++i ) tmp[i] = a[x+i];
- for( int i = 0; i < h; ++i ) {
- cw = w*tmp[i+h];
- a[x+i] = tmp[i] + cw;
- a[x+h+i] = tmp[i] - cw;
- w = w*W;
- }
- }
- inline void conv( comp *a, comp *b, int n ) {
- for( int i = 0; i < n; ++i ) c[i] = b[i];
- fft( a, 0, n, +1 );
- fft( c, 0, n, +1 );
- for( int i = 0; i < n; ++i )
- a[i] = a[i]*c[i];
- fft( a, 0, n, -1 );
- for( int i = 0; i < n; ++i ) {
- a[i].y = 0.0;
- a[i].x = round( a[i].x/n+0.2 );
- }
- }
- inline void solve( comp *p, int *q, int *r, int n ) {
- for( int i = 0; i < n; ++i ) s[i] = p[i];
- conv( s, p, n );
- for( int i = 0; i < n; ++i )
- s[i].x -= 3*q[i];
- conv( s, p, n );
- for( int i = 0; i < n; ++i )
- s[i].x += 2*r[i];
- }
- int main( void )
- {
- scanf( "%d", &N );
- for( int i = 0; i < N; ++i ) {
- int a; scanf( "%d", &a );
- p[a+shift] = comp( 1.0, 0.0 );
- q[2*a+2*shift] = 1;
- r[3*a+3*shift] = 1;
- }
- solve( p, q, r, 1 << 16 );
- for( int i = 0; i < deg; ++i ) {
- if( fabs( s[i].x ) < eps ) continue;
- printf( "%d : %lld\n", i-3*shift, (llint)( s[i].x+0.1 )/6 );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement