CodeForces
来源:互联网 发布:程序员第一天上班想哭 编辑:程序博客网 时间:2024/06/05 19:52
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.
10
10 5 1
4
4 2 1
3
3 1
#include<stdio.h>#define maxn 1000000+10#define max(a,b) (a>b?a:b)int p[maxn/10],c[maxn];void is_prim()//线性筛法{ int tot=0,i,j; c[0]=1,c[1]=1; for(i=2; i<=maxn; i++) { if(!c[i]) p[tot++]=i; for(j=0; j<tot&&i*p[j]<maxn; j++) { c[i*p[j]]=1; if(!(i%p[j])) break; } }}int main(){ is_prim(); int n; scanf("%d",&n); printf("%d ",n); int ps=0; while(n!=1) { if((n%p[ps])==0) { n/=p[ps]; printf("%d ",n); } else ps++; } return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Map接口
- C# 输入法
- 文章标题
- DB2调用 get_dbsize_info的时候,报错SQL0443N和SQL0572N:
- 2017.03.15
- CodeForces
- Java 之内部类
- 哈希表简介
- x64平台AT&T汇编实现快速排序函数
- Java进阶(五)Java I/O模型从BIO到NIO和Reactor模式
- 莫队算法学习笔记
- 三天打鱼两天晒网
- The SDK platform-tools version (24.0.4) is too old to check APIs compiled with API 25
- UNIX常用命令行指令(3)(基本输入输出操作)