Codeforces Beta Round #54 (Div. 2)——B

B. Coins
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.

Input

The first and only line contains an integer n (1 ≤ n ≤ 106) which represents the denomination of the most expensive coin.

Output

Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination n of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.

题意分析:生成保证一个数是前面出现所有数的约数的数组,保证数组最长。

思路:只要枚举前一个数的所有约数,只要这个数能将前面一个数整除,必然能将前面的所有的数整除。

贪心思想:保证当前生出的约数最大,后面可找到更多的数。

#include <iostream>

using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<n;
    while(n>1)
    {
        int i;
        for(i=2;i<n;i++)
            if(n%i==0)
            {
                n=n/i;
                cout<<" "<<n;
                break;
            }
        if(i==n) {cout<<" "<<1;break;}
     }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值