Codeforces Round #272 (Div. 2) A
来源:互联网 发布:lua调用java 编辑:程序博客网 时间:2024/06/16 16:35
题目:
题意分析:
水题一枚,给出一个N。然后分解N,只能分解为1和2。考虑全部分解为1的情况,则最多需要N步,全部分解为2的情况,如果为奇数N/2+1 偶数N/2.然后枚举,验证就行了。
代码:
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namespace std;int main(){ int n,m,i; while(scanf("%d%d",&n,&m)!=EOF) { if(n%2==0) { for(i=n/2;i<=n;i++) { if(i%m==0) { printf("%d\n",i); break; } } if(i==n+1) printf("-1\n"); } if(n%2==1) { for(i=n/2+1;i<=n;i++) { if(i%m==0) { printf("%d\n",i); break; } } if(i==n+1) printf("-1\n"); } } return 0;}
0 0
- Codeforces Round #272 (Div. 2) A
- Codeforces Round #272 (Div. 2) A
- Codeforces Round #272 (Div. 2) A Dreamoon and Stairs
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- Codeforces Round #138 (Div. 2) A题
- Codeforces Round #147 (Div. 2) A题
- Warshall算法C++实现
- Resharper上手指南
- oralce的系统用户system的输入口令怎么找回?遇见ORA-28000: the account is locked怎么解锁?
- IT痴汉的工作现状17-健康警钟
- HDU 3397 Sequence operation(线段树)
- Codeforces Round #272 (Div. 2) A
- Trie实践:一种比哈希表更快的数据结构
- 【LeetCode】Sort Colors 解题报告
- Sublime 安装 package control 组件
- JavaScript实现功能全集
- 基于ARM-Linux系统开发平台下嵌入式MP3的设计与实现
- Floyd算法Cpp实现
- 省赛总结及感悟
- 浅析C++中临时匿名对象