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;
    }
  • 相关阅读:
    web页面性能优化之接口前置
    python大佬养成计划----flask_bootstrap装饰网页
    撸个查询物流的小程序,欢迎体验
    FullCalendar插件的基本使用
    GeekforGeeks Trie
    使用Django和Python创建Json response
    nginx-gridfs的安装
    Linux kernel config and makefile system
    hadoop日志分析
    安装STS报错(三)
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781917.html
Copyright © 2011-2022 走看看