因为痛,所以叫青春

我有一个梦想:穷屌丝变身富屌丝
uvaUVa 10392 - Factoring Large Numbers

简单,读题加AC用了很短的时间,我自己单独把题目意思揣摩出来的,呵呵

View Code
#include<stdio.h>
#include<math.h>
int main()
{
    long long f[50000], n, i, k, m;
    k = 0;
    for(n = 2;k < 50000;n++)
    {
        for(i = 2;i < sqrt(n)+1; i++)
        {
            if(n%i == 0)
                break;
        }
        if(i > sqrt(n))
            f[k++] = n;
    }
    while(scanf("%lld",&n) && (n > 0))
    {
        i = 0;
        while(n)
        {
            while(n%f[i] == 0)
            {
                printf("    %lld\n",f[i]);
                n /= f[i];
            }
            i++;
            if(n < f[i] || i > 49999)break;
        }
        if(n>1)
            printf("    %lld\n",n);
        printf("\n");
    }
    return 0;
}

 

posted on 2012-08-02 09:47  Nice!  阅读(226)  评论(0编辑  收藏  举报