CodeForces - 58B Coins(水题。。大水题)
2017-03-17 12:47
309 查看
题目:
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.
Examples
input
output
input
output
input
output
思路:
我还能说什么。。。这么水的一个题我比赛竟然没写?思路就是。。暴力
代码1(c++):
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define N (2000+20)
#define M 200010#define MOD (1000000000+7)
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
int main()
{
int n,i;
scanf("%d",&n);
for (i=n; i>0; i--)
if(n%i==0)
printf("%d ",n=i);
return 0;
}
代码2(python3):
n=int(input())
for i in range(n,0,-1):
if n%i==0:
n=i
print(n)
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.
Examples
input
10
output
10 5 1
input
4
output
4 2 1
input
3
output
3 1
思路:
我还能说什么。。。这么水的一个题我比赛竟然没写?思路就是。。暴力
代码1(c++):
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define N (2000+20)
#define M 200010#define MOD (1000000000+7)
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
int main()
{
int n,i;
scanf("%d",&n);
for (i=n; i>0; i--)
if(n%i==0)
printf("%d ",n=i);
return 0;
}
代码2(python3):
n=int(input())
for i in range(n,0,-1):
if n%i==0:
n=i
print(n)
相关文章推荐
- CodeForces 20B Equation 水题
- Codeforces--630A--Again Twenty Five! (水题)
- Codeforces 237A Free Cash(水题吧)
- 【水题】CodeForces - 233A Perfect Permutation
- Codeforces 644A Parliament of Berland 【水题】
- codeforces 655A A. Amity Assessment(水题)
- CodeForces 705B Spider Man (水题)
- CodeForces 589I Lottery (暴力,水题)
- Codeforces 460A Vasya and Socks(水题)
- codeforces 652C Foe Pairs 水题
- codeforces 658A A. Bear and Reverse Radewoosh(水题)
- Codeforces 450A Jzzhu and Children(水题)
- CodeForces 631A Interview(水题)
- Codeforces--616B--Dinner with Emma(模拟水题)
- CodeForces水题
- codeforces 707A A. Brain's Photos(水题)
- Codeforces 825D Suitable Replacement【贪心】水题
- codeforces 665B B. Shopping(水题)
- CodeForces 711A Bus to Udayland (水题)
- Diverse Permutation - CodeForces 482 A 水题