Content
给定一个数 ,你可以对其进行以下操作若干次,直到无法再操作:
- 选择一个数 满足 且 ,并将 变为 。
现在有以下两种询问共 个:
-
1 x:给定 ,求 最多能进行几次操作; -
2 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;
}