炸鸡块君的高中回忆 (数论 模拟

2022/1/25 6:05:50

本文主要是介绍炸鸡块君的高中回忆 (数论 模拟,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

添加链接描述
先模拟前(n-m)/(m-1)*2

#include<bits/stdc++.h>
using namespace std;
const int N=1100;
#define int long long
typedef long long ll;
signed main(){
    int T;
    cin>>T;
    while(T--){
        int n,m;
        ll res=0;
        cin>>n>>m;
        if(m==1&&n!=1){
            puts("-1");
            continue;
        }
        else if(m==1&&n==1){
            puts("1");
            continue;
        }
        if(n<=m){
            puts("1");
        }
        else {
            
            ll p=(n-m)/(m-1);
            ll res=p*2;
            ll now=p*(m-1);
            n-=now;
            while(n>0){
                if(n<=m){
                    res++;
                    break;
                }
                n-=m-1;
                res+=2;
            }
            // cout<<p<<endl;
        cout<<res<<endl;
        }
        
    }
    
    return 0;
}


这篇关于炸鸡块君的高中回忆 (数论 模拟的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程