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

10分钟把代码搞定,结果竟然TLE,于是第一次打了表,结果还算TLE,哥郁闷了,回到原来代码,优化后终于AC了。

Posted by sicojuy at 2010-11-30 23:16:36 on Problem 2262
Source Code

Problem: 2262		User: sicojuy
Memory: 156K		Time: 235MS
Language: C		Result: Accepted
Source Code

#include <stdio.h>
#include <math.h>

int main()
{
    long n, i, j, k, m;
    while(scanf("%ld", &n), n)
    {
        for(i = 3; i < 500000 ; i += 2)
        {
            m = sqrt(i) + 1;
            for(j = 3; j < m; j += 2)
                if(i % j == 0)
                    break;
            if(j >= m)
            {
                k = n - i;
                m = sqrt(k) + 1;
                for(j = 3; j < m; j += 2)
                    if(k % j == 0)
                        break;
                if(j >= m)
                {
                    printf("%ld = %ld + %ld\n", n, i, k);
                    break;
                }
            }
        }
    }
    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