|
|
back to boardtest #3 is quite werid // why wa, i was really confused #include <stdio.h> #define MAXN 1002 int perm[ MAXN ] ; void swap(long long* x,long long* y ) { long t = *x; *x = *y; *y = t; } long long gcd(long long m,long long n) { long r; if( m < n ) swap( &m,&n ); do{ r = m % n ; m = n; n = r; }while( r ); return m; } int main() { int size , i, mark, q[ MAXN ] ; long long t[ MAXN ] ; while( scanf("%d",&size ) != EOF ){ for( i = 1 ; i <= size; i++ ){ scanf("%d",&perm[ i ]); q[ i ] = perm[ i ] ; t[ i ] = 1; } for( i = 1; i <= size; i++ ) for( ; i != perm[ i ] ; t[ i ]++ ) perm[ i ] = q[ perm[ i ] ] ; for( i = 1; i <= size - 1; i++ ) t[ i ] = ( t[ i ] / gcd( t[ i ],t[ i + 1 ] ) ) * t[ i + 1 ] ; printf("%I64d\n",t[ i - 1 ] ); for( i = 1 ; i <= size; i++ ) t[ i ] = 1; } return 0; } Re: test #3 is quite werid Tests for your program: 1 1 5 2 1 4 5 3 Use for( i = 1; i <= size - 1; i++ ) t[ i + 1 ] = ( t[ i ] / gcd( t[ i ],t[ i + 1 ] ) ) * t[ i + 1 ] ; printf("%I64d\n",t[ i ] ); instead of for( i = 1; i <= size - 1; i++ ) t[ i ] = ( t[ i ] / gcd( t[ i ],t[ i + 1 ] ) ) * t[ i + 1 ] ; printf("%I64d\n",t[ i - 1 ] ); Edited by author 26.08.2007 14:50 |
|
|