zoukankan      html  css  js  c++  java
  • Avito Cool Challenge 2018-A. Definite Game(思维题)

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.

    He came up with the following game. The player has a positive integer nn. Initially the value of nn equals to vv and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer xx that x<nx<n and xx is not a divisor of nn, then subtract xx from nn. The goal of the player is to minimize the value of nn in the end.

    Soon, Chouti found the game trivial. Can you also beat the game?

    Input

    The input contains only one integer in the first line: vv (1≤v≤1091≤v≤109), the initial value of nn.

    Output

    Output a single integer, the minimum value of nn the player can get.

    Examples

    input

    Copy

    8
    

    output

    Copy

    1
    

    input

    Copy

    1
    

    output

    Copy

    1
    

    Note

    In the first example, the player can choose x=3x=3 in the first turn, then nn becomes 55. He can then choose x=4x=4 in the second turn to get n=1n=1 as the result. There are other ways to get this minimum. However, for example, he cannot choose x=2x=2 in the first turn because 22is a divisor of 88.

    In the second example, since n=1n=1 initially, the player can do nothing.

    题意:你可以选小于n的数x,并且这个数不能是n的约数,可以不选,然后n=n-x,然后在进行,直到最小的数。

    题解:

    我们可以通过直接选n-1,就得到了最小的1,但是要考虑2的情况,因为1是2的约数,故2的时候最小为2

    代码非常简单

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    
    using namespace std;
    
    int main()
    {
    	int n;
    	cin>>n;
    	if(n==2)
        {
        	cout<<2<<endl;
    	}
    	else
    	{
    		cout<<1<<endl;
    	}
    	return 0;
    }
  • 相关阅读:
    结构体位域与规范定义顺序的问题
    visual studio 2015使用MFC的console调试打印
    MFC笔记
    MFC中解决文本保存到文件时乱码问题
    C/C++关于文件的读写操作以及文件的打开和保存
    MFC使用自定义消息
    MFC输入框CEdit控件十六进制转换
    Visual studio C++ MFC应用程序自动探测串口号
    visual C++ MFC串口编程overlapped结构汇总
    模块及模块间的接口方式
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781917.html
Copyright © 2011-2022 走看看