P11747 「TPOI-1A」鞋子特大号
liaoxingrui · · 题解
Content
给定一个数
- 选择一个数
y 满足1 \le y < x 且\gcd ( x , y ) \not = 1 ,并将x 变为\gcd ( x , y ) 。
现在有以下两种询问共
-
1 x:给定x ,求x 最多能进行几次操作; -
2 q:给定q ,求出一个最小的x ,使得x 最多能进行恰好q 次操作。
Solution
这两种询问都是要求出最多能进行多少次操作,而每次操作的
还需要注意:
第二个操作要用 unsigned long long。
Code
#include<bits/stdc++.h>
using namespace std;
int t,x,opt;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
cin>>opt>>x;
if(opt==1){
int cnt=0;
for(int i=2;i<=sqrt(x);i++)
while(x%i==0){
cnt++;
x/=i;
}
if(x!=1)
cnt++;
cout<<max(0,cnt-1)<<endl;
}
else
cout<<((unsigned long long)1<<x+1)<<endl;
}
return 0;
}