Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么会TLE// Least common multiple #include <cstdio> long long lcm( long long a, long long b ) { long long r, mul; r = a % b; mul = a * b; while ( r ) { a = b; b = r; r = a % b; } return mul / b; } int main() { int i, t, n; long long ans, num; scanf("%d",&t); while ( t-- ) { scanf("%d", &n); ans = 1; while ( n-- ) { scanf("%lld", &num); ans = lcm( ans, num ); if ( ans > 1e9 ) break; } if ( n == -1 ) printf("%lld\n",ans); else printf("More than a billion.\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator