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;
    }
  • 相关阅读:
    webim-界面细节调整
    使用PHP得到所有的HTTP请求头_还有应答头
    Bootstrap学习的点点滴滴
    asterisk中eyebeam与移动的IMS帐号对接
    总结Ajax跨域调用问题
    Spring【基础】-注解-转载
    Spring-【高阶】注解-转载
    让你的IDEA倍爽
    IDEA的git密码修改
    Idea设置签名
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781916.html
Copyright © 2011-2022 走看看