June 30, 2010

a010

#include <iostream>
#include <math.h>

using namespace std;

int
is_prime(long x)
{
    int i;

    if (x < 2)
    return 1;

    for(i = 2; i <= sqrt(x); ++i)
    {
    if (x % i == 0)
    return 0;
    }
   
    return 1;
}

int
main()
{
    long x;
    int a, b;
   
    a = 1;
    b = 0;

    while(cin >> x)
    {
    if (is_prime(x))
    cout << x << endl;
    else
    {
    while(x > 1)
    {
    a++;
   
    if (is_prime(a))
    {
    if (x % a == 0)
    {
    cout << a;
    b = 0;
   
    while (x % a == 0)
    {
    b++;
    x = x / a;
    }

    if (b > 1)
    cout << "^" << b;
    if (x > 1)
    cout << " * ";
    }
    }
    }
   
    cout << endl;
    a = 1;
    }
    }
   
    return 0;
}

0推薦此文章
Today's Visitors: 0 Total Visitors: 15
Personal Category: Uncategorized Articles Topic: creation / literature / poetry
[Trackback URL]

Reply
  • 1樓

    1樓搶頭香

    安安阿,我是小楓,逛到你家,跟你分享這個好康^^

    直接點小房子進去看囉就看的到囉^^

  • at July 14, 2012 02:44 AM comment | Homepage
Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0