D. Olya and magical square (数学规律题)

详细加图文讲解

 

 

 

D. Olya and magical square (数学规律题)
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;

const int N = 1e6 + 5;

LL C[105];

int main() {
    rep(i, 1, 31) C[i] = C[i - 1] * 4LL + 1LL;
    int _; scanf("%d", &_);
    while(_--) {
        LL n, k;
        scanf("%lld %lld", &n, &k);
        if(n > 31) {
            printf("YES %lld\n", n - 1); continue;
        }
        LL res = 0LL, now = 1, j = 0, tmp = 0LL;
        while(res + now <= k && j < n) {
            res += now;
            now = now * 2 + 1;
            j++;
            tmp += C[n - j] * (now - 2LL);
        }
        if(k > res + tmp) puts("NO");
        else printf("YES %lld\n", n - j);
    }
    return 0;
}
View Code

 

上一篇:[Kevin英语情报局]那些年我们说过的中式英语


下一篇:Centos7 系统更改apache默认网站目录(解决You don't have permission to access / on this server问题)