Codeforces Round #685 (Div. 2) A

Codeforces Round #685 (Div. 2) A

大意

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

  1. 除以一个 \(N\) 的因数(不等于 \(N\)
  2. 减一

问:

将原数变成一最少需要几步。

思路

提交错了...

分类讨论:

\(N\)\(1,2,3\) ,答案是 \(0,1,2\)

\(N\) 为大于二的偶数,显然需要两步。

\(N\) 为大于三的奇数,显然需要三步,其中一步用来变成偶数。

代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

#define ll long long
#define ull unsigned long long
#define cint const int&
#define Pi acos(-1)

const int mod = 998244353;
const int inf_int = 0x7fffffff;
const ll inf_ll = 0x7fffffffffffffff;
const double ept = 1e-9;

int t, n;

int main() {
    cin >> t;
    while(t--) {
        cin >> n;
        if(n==1) cout << 0 << endl;
        else if(n==2) cout << 1 << endl;
        else if(n==3) cout << 2 << endl;
        else if(!(n%2)) cout << 2 << endl;
        else cout << 3 << endl;
    }
    return 0;
}
posted @ 2020-11-22 19:47  ullio  阅读(64)  评论(0编辑  收藏  举报