Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么会TLE

Posted by fanhr at 2013-05-20 18:27:25 on Problem 3002
// 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator