221 字
1 分钟
CF1988A-Split the Multiset 题解
CF1988A
题意简述
给定一个正整数 ,每次可以将其拆分成 个数,求将 变为 个 的最少操作次数。
题目分析
对于一个数 ,我们每次可以将其拆分为 个 ,和 个 ,所以只需要暴力枚举 能被拆分几次,就可以得出答案,具体见下:
当 时:
不难发现只需要每次将 减去 ,一直减到 ,此时的操作次数即为答案。
Code
#pragma GCC optimize(1, 2, 3, "Ofast", "inline")#include <bits/stdc++.h>using namespace std;#define ll long long#define int ll#define ONLINE_JUDGE#define MULTI_CASESconst int MaxN = 2e5+100;const int INF = 1e9;int T=1, N, M;int a[MaxN];int ans=0;inline void Solve(){ cin>>N>>M; if(N==1){ cout<<0<<endl; return ; } ans=0; for(int i=1;;i++){ N-=M-1;// cout<<N<<endl; ans++; if(N<=1){ break; } } cout<<ans<<endl;}signed main(){#ifndef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout);#endif ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
#ifdef MULTI_CASES cin >> T; while (T--)#endif Solve(); //fclose(stdin); //fclose(stdout); return 0;}
CF1988A-Split the Multiset 题解
https://blog.introl.top/posts/cf1988a-split-the-multiset-题解/