首先我们先来回忆一下小学一年级就学过的知识:任何一个偶数都是 \(2\) 的倍数,那么我们就可以分成两种情况考虑:奇数和偶数。

对于偶数,我们可以直接将其输出,因为它必定能被 \(2\) 与它自己整除(第一段中有提到)。

对于奇数,我们需要将它变成一个偶数,并且改变后的偶数还要被 \(a\) 本身整除,因此,我们可以直接将 \(a \times 2\),这样就是一个既可以被 \(2\) 整除又可以被 \(a\) 本身整除的数了。

通过上面的分析,我们将其整理后,思路如下。

如果 \(a\) 是偶数,直接输出;

如果 \(a\) 是奇数,将其 \(\times 2\) 后输出。

得出代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
int a;
cin>>a;
if(a%2==0)cout<<a;
else cout<<a*2;
return 0;
}

题解 AT4164 【[ABC102A] Multiple of 2 and N】的更多相关文章

  1. [POJ2356]Find a multiple 题解(鸽巢原理)

    [POJ2356]Find a multiple Description -The input contains N natural (i.e. positive integer) numbers ( ...

  2. 题解报告:poj 1426 Find The Multiple(bfs、dfs)

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

  3. HDU 1019 Least Common Multiple 数学题解

    求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...

  4. Lowest Common Multiple Plus 题解

    求n个数的最小公倍数. Input输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行.你可以假设最后的 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. LeetCode Read N Characters Given Read4 II - Call multiple times

    原题链接在这里:https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/ 题目: The ...

  7. NBUT1541 Rainwater 题解

    http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1541 When rain, nocLyt discovered a magical phenomeno ...

  8. Find The Multiple 分类: 搜索 POJ 2015-08-09 15:19 3人阅读 评论(0) 收藏

    Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21851 Accepted: 8984 Sp ...

  9. 158. Read N Characters Given Read4 II - Call multiple times

    题目: The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the ...

随机推荐

  1. 【转】Android WiFi 经常掉线出现的几个原因分析!

    原因1.从Log分析来看,这个是由于Dhcp request fail 导致最终disconnect . Log 分析如下: 16:53:31.659 958 6525 D NetUtils: dhc ...

  2. light oj 1214 - Large Division 大数除法

    1214 - Large Division Given two integers, a and b, you should check whether a is divisible by b or n ...

  3. 利用VS Code在Azure上构建部署静态页面

    0x00 前言 前一段时间,我找到了Jendrik Illner的个人网站.除了那里的精彩文章,网站的主题也吸引了我的注意力,而且我发现该网站的主题采用了Hugo的Academic主题. 然后,我认为 ...

  4. python函数定义中引用外部变量的一个问题

    如果在函数定义的默认值中引用了一个外部变量,如下所示 x = 3 def func(a = x): print(a, x) 那么a的默认值就会是3, 但是print语句中的x会是调用时的x值 lamb ...

  5. codewars--js--Human Readable Time—Math对象,parseInt()

    问题描述: Write a function, which takes a non-negative integer (seconds) as input and returns the time i ...

  6. Caliburn.Micro框架之Action Convertions

    首先新建一个项目,名称叫Caliburn.Micro.ActionConvertions 然后删掉MainWindow.xaml 然后去app.xaml删掉StartupUri这行代码 其次,安装Ca ...

  7. MySQL基础(4) | 视图

    MySQL基础(4) | 视图 基本语法 1.创建 CREATE VIEW <视图名> AS <SELECT语句> 语法说明如下. <视图名>:指定视图的名称.该名 ...

  8. 用Markdown编写

    计算机视觉 图像分类 对象检测 目标检测 图像分割 语义分割 实例分割

  9. [CF1311C] Perform the Combo

    Solution 前缀和搞一下即可 #include <bits/stdc++.h> using namespace std; #define int long long const in ...

  10. 【算法】——递归:小白正在上楼梯,楼梯有n阶台阶,小白一次可以上1阶,2阶或者3阶,实现一个方法,计算小白有多少种走完楼梯的方式。

    分析:从最后一步分析,能有的情况有三种情况构成,写出如图所示的方程 //和斐波拉契相似 int void f(int n) { //考虑出口 ) ;//正常思路是返回0 ) ;//通过自己想可以得出只 ...