#20159: c++ Ans


jamesangle08270323@gmail.com (Angle0james)

學校 : 不指定學校
編號 : 111700
來源 : [210.71.2.39]
最後登入時間 :
2020-06-23 13:59:56
a010. 因數分解 | From: [210.71.2.39] | 發表日期 : 2019-12-10 14:37

#include<stdio.h>
int main()
{
    int  number,factor,times;

    while(scanf("%d",&number)!=EOF)
    {   
        if(number==1)
            printf("%d\n",1);

        else    
        for(factor=2;factor<=number;factor++)
        {
            times=0;
            while(number%factor==0)
            {
                number/=factor;
                times++;
            }

            if(number==1)
            {
                if(times>1)
                    printf("%d^%d\n",factor,times);
                else if(times==1)
                    printf("%d\n",factor);
            }    
            else 
            {
                if(times>1)
                    printf("%d^%d * ",factor,times);
                else if(times==1)
                    printf("%d * ",factor);
            }    
        }    
    }
    return 0;
}
 
#20464: Re:c++ Ans


hansen033 (HC)

學校 : 新北市私立南山高級中學
編號 : 71998
來源 : [1.34.134.110]
最後登入時間 :
2024-06-01 00:07:51
a010. 因數分解 | From: [1.161.17.195] | 發表日期 : 2020-01-27 16:32

#include
int main()
{
    int  number,factor,times;

    while(scanf("%d",&number)!=EOF)
    {   
        if(number==1)
            printf("%d\n",1);

        else    
        for(factor=2;factor<=number;factor++)
        {
            times=0;
            while(number%factor==0)
            {
                number/=factor;
                times++;
            }

            if(number==1)
            {
                if(times>1)
                    printf("%d^%d\n",factor,times);
                else if(times==1)
                    printf("%d\n",factor);
            }    
            else 
            {
                if(times>1)
                    printf("%d^%d * ",factor,times);
                else if(times==1)
                    printf("%d * ",factor);
            }    
        }    
    }
    return 0;
}

題目說會大於1

 
ZeroJudge Forum