NYOJ 505 因子和阶乘

http://acm.nyist.net/JudgeOnline/problem.php?pid=509 题意:中文题目。。。 思路:快速筛即可。。。妈蛋。。。这个oj不能用宏编译==。。。然后一直TLE...去掉了就好了。。sad

/* ***********************************************
Author :111qqz
Created Time :2016年01月20日 星期三 13时53分54秒
File Name :code/nyoj/509.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6const int N=10500;
 7int n;
 8int pri[N]={0};
 9int npri[N]={1,1};
10int num[N];
11int cnt;
1void pre()
2{
3    cnt = 0 ;
4    for ( int i = 2 ; i < N  ; i++)
5    {
6	if (!npri[i]) pri[cnt++] = i;
1	    for ( int j = 0 ; j < cnt &&i*pri[j]<N  ;j++)
2	    {
3		npri[i*pri[j]] = 1;
4		if (!(i%pri[j])) break;
	    }
	
    }
//    for ( int i = 0 ; i <= 100 ; i++) printf("%d ",pri[i]);
 1}
 2void solve ( int x)
 3{
 4    for ( int i = 2 ; i <= x ; i++)
 5    {
 6	int tmp =  i;
 7	for ( int j = 0 ; j < cnt ; j++)
 8	{
 9	    while (tmp%pri[j]==0)
10	    {
11		tmp/=pri[j];
12		num[j]++;
 1	    }
 2	    if (tmp==1) break;
 3	}
 4    }
 5    for ( int i = 0 ; i < cnt ; i++)
 6    {
 7	if (pri[i]>x) break;
 8	printf("%d ",num[i]);
 9    }
10}
11int main()
12{
13	#ifndef  ONLINE_JUDGE 
14//	freopen("code/in.txt","r",stdin);
15  #endif
 1	pre();
 2	int T;
 3	cin>>T;
 4	while (T--)
 5	{
 6	    ms(num,0);
 7	    scanf("%d",&n);
 8	    solve(n);
 9	    puts("");
10	}
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}