D. Ceil Divisions 题解(思维)

题目链接

题目思路

要对数字充满感觉

1e5 20 那么就是log

1e5 5 那么就是loglog

而loglog就是开根号 然后就用开根号的思维去写即可

代码

#include<bits/stdc++.h>
#define fi first
#define se second
#define debug cout<<"I AM HERE"<<endl;
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-6;
int n;
signed main(){
    int _;cin>>_;
    while(_--){
        cin>>n;
        vector<pii> ans;
        while(n>2){
            int s=ceil(sqrt(n));
            for(int i=s+1;i<n;i++){
                ans.push_back({i,i+1});
            }
            ans.push_back({n,s});
            ans.push_back({n,s});
            n=s;
        }
        cout<<ans.size()<<'
';
        for(auto x:ans){
            cout<<x.fi<<" "<<x.se<<'
';
        }
    }

    return 0;
}

不摆烂了,写题
原文地址:https://www.cnblogs.com/hunxuewangzi/p/15244607.html