PersonalCorpus 版 (精华区)

Your C++ program has solved Ok the problem 583 (Prime Factors)
in 7.370 seconds using as much as 404 kbytes of virtual memory.

void main()
{
    int i,j,k;
    int a[1000];
    while (1) {
        scanf("%d\n",&k);
        if (k==0) break;
        printf("%d = ",k);
        if (k<0) { a[0]=-1; k=-k; j=1; } else j=0;
        i=2;
            while (k%i==0) {
                k/=i;
                a[j++]=i;
            }
        for (i=3;i<=floor(sqrt(k));i+=2) {
            while (k%i==0) {
                k/=i;
                a[j++]=i;
            }
            if (k==1) break;
        }
        if (k>1) a[j++]=k;
        for (i=0;i<j-1;i++) printf("%d x ",a[i]);
        printf("%d\n",a[j-1]);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.024毫秒