Demo entry 5853523

   

Submitted by anonymous on Jul 20, 2016 at 13:36
Language: C++. Code size: 810 Bytes.

#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
int visited[100010];
vector<int>a[100010];
void init()
{
    int i,j;
    for(i=0;i<100010;i++)
       a[i].clear();//vector的清空
    memset(visited,0,sizeof(visited));
    for(i=2;i<=100000;i++)
    {
        if(visited[i]==0)//i是素数这是可以保证的
        {
            a[i].push_back(i);
            for(j=i+i;j<=100000;j+=i)//筛选素数,其实这种方法没以前那种素数法快,但是这里用来求一个数的质因子就比较好了
            {
                visited[j]=1;
                a[j].push_back(i);
            }
        }
    }
}
int main()
{
    int i,j;
    init();
    for(i=0;i<=50;i++)
    {
        printf("%d:",i);
        for(j=0;j<a[i].size();j++)
            printf("%d ",a[i][j]);
        printf("\n");
    }
    return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).