「TPOI-1A」鞋子特大号 题解
签到题。
先看 1 询问:
分析一次操作,例如
那么为了尽可能多地操作,我们只需要保证一次删去一个质因子即可,那么记初始
于是我们直接
再看 2 询问:
给定
那么既然能进行
最终的时间复杂度为 unsigned long long。
#include <bits/stdc++.h>
using namespace std;
bool isp(int x) {
if(x <= 1) return false;
for(int i = 2;i * i <= x;i++) {
if(x % i == 0) return false;
}
return true;
}
int main() {
int t; cin >> t;
while(t--) {
int opt,x; cin >> opt >> x;
if(opt == 1) {
int cnt = 0;
for(int i = 2;i * i <= x;i++) {
if(x % i == 0 && isp(i)) {
while(x % i == 0) {cnt++; x /= i;}
if(x == 1) {cnt--; break;}
}
}
cout << cnt << endl;
}
else {
unsigned long long p = 1;
for(int i = 1;i <= x+1;i++) p *= 2;
cout << p << endl;
}
}
return 0;
}