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

AC了的代码,关键部分换成了内嵌汇编,为什么总是TLE呢?

Posted by mmx at 2008-10-18 13:47:53 on Problem 3604
#include <stdio.h>
#define maxn 5000004
#define maxr 2236
char mk[maxn];
int prime[350000], pnum, c[32];

void init()
{
    int i, j;
    for(i=0;i<32;i++)
        c[i]= (i+2)*(i+2)*(i+1)*(i+1)>>2;
    for(i=2;i<maxn;i++)if(!mk[i])
    {
        prime[pnum++]=i;
        if(i<maxr)for(j=i*i;j<maxn;j+=i)mk[j]=1;
    }
}
int main()
{
    int i, j, ncase, n, res;
    init();
    scanf("%d", &ncase);
    while(ncase--)
    {
        scanf("%d", &n);
        res=1;
        for(i=0;i<pnum;i++)
            if(!mk[n])
            {
                if(n>1)res *=c[1];
                break;
            }
            else
            {
                j=0;
                __asm{
				mov ecx, i
				mov eax, n
LI:				cdq
				idiv prime[ecx*4]
				test edx, edx
				jne LO
				inc j
				jmp LI
LO:
				}

                if(j>0)res *=c[j];
            }
        printf("%d\n", res);
    }
    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