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 |
AC了的代码,关键部分换成了内嵌汇编,为什么总是TLE呢?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator