题解 CF1451A 【Subtract or Divide】

题目大意

给你一个数 \(n\) ,你可以对他进行如下操作:

  • 除以它的因子(\(n\) 本身除外)。
  • \(n\) 减一。

解法

对于这题,我们可以想想如何对数字进行转化。

首先,我们可以明显地看出,对数字 \(1\) 我们不需要转化,即答案为 \(0\) 。对于数字 \(2\) 我们只需要减一即可,答案为 \(1\)

其次,对于偶数(\(2\) 除外),显然必定有一个因子可以使它变为 \(2\) ,故答案必定为 \(2\)

然后,对于奇数(\(1\)\(3\) 除外),只要减一就会变为偶数,再变成 \(1\) ,故答案必定为 \(3\)

特别的,因为 \(3\) 减一后变为 \(2\) 所以此时答案为 \(2\)

Code

#include <iostream>
#include <cstdio>
using namespace std;
int t;
int main()
{
	cin>>t;
	while(t--)
	{
		int k;
		cin>>k;
		if(k==2) cout<<1<<endl;
		else if(k==1) cout<<0<<endl;
		else if(k%2==0||k==3) cout<<2<<endl;
		else cout<<3<<endl;
	}
	return 0;
}
posted @ 2020-12-02 11:59  -lala-  阅读(162)  评论(0)    收藏  举报