Codeforces Beta Round #54 (Div. 2)——B
来源:互联网 发布:通达信股票软件编程 编辑:程序博客网 时间:2024/05/21 12:50
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.
The first and only line contains an integer n (1 ≤ n ≤ 106) which represents the denomination of the most expensive coin.
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;}
- Codeforces Beta Round #54 (Div. 2)——B
- Codeforces Beta Round #96 (Div. 2)——B
- Codeforces Beta Round #93 (Div. 2 Only)——B
- Codeforces Beta Round #91 (Div. 2 Only)——B
- Codeforces Beta Round #89 (Div. 2)——B
- Codeforces Beta Round #18 (Div. 2 Only)——B
- Codeforces Beta Round #44 (Div. 2)——B
- Codeforces Beta Round #46 (Div. 2)——B
- Codeforces Beta Round #52 (Div. 2)——B
- CodeForces 581B Luxurious Houses(简单题)——Codeforces Beta Round #322 (Div. 2)
- Codeforces Beta Round #65 (Div. 2)——A,B,C
- Codeforces Beta Round #67 (Div. 2)——A,B,C
- Codeforces Beta Round #69 (Div. 2 Only)——A,B,D
- Codeforces Beta Round #70 (Div. 2)——A,B,C
- Codeforces Beta Round #72 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #73 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #76 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #77 (Div. 2 Only)——A,B,C
- 显示无法删除nul,参数不正确 的解决之道
- maven pom.xml详解
- [HTML] 使用HTML5的本地存储localStorage
- linux调度器(一)——概述
- 0001
- Codeforces Beta Round #54 (Div. 2)——B
- RUP 与UML
- JS数组去重函数
-
- 用vs调试sql存储过程
- Myeclipse中Ant编译文件停止的问题
- framebuffer驱动分析
- 最大和的子数组 Maximum subarray problem
- 由UIImageView中的UIButton不响应事件引发的