题意
给定一个长度为 的对数序列 ,对于 ,有 。
然后有 组询问,给出一个位置 。求修改 后使序列仍是对数序列最少操作次数,操作中不能再修改 。若无解,输出 。
思路
由于 可得 ,因此当 为 时, 必须为 。所以无法修改第 个位置,答案为 。
当 时,找出它的最大值质因子 ,所有为 的倍数()都要修改, 本身除外。所以答案为 。
单次查询时间复杂度为 。
AC CODE
AC code
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1 << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n';
using namespace std;
const int N = 2e5 + 10 , M = 2e5 + 10;
const int mod = 1e9 + 7;
ll n , x , q , lst , pos;
inline void sol(ll x){//找x的最大质因子
pos = x;
for (ll i = 2 ; i * i <= pos ; i ++) while(x % i == 0) x /= i , lst = max(lst , i);
if (x > 1) lst = max(lst , x);//x没有分解完
}
inline void solve(){
cin >> n >> q;
while(q --) cin >> x , lst = 1 , sol(x) , cout << ((x == 1) ? -1 : (n / lst - 1)) << '\n';//x为1无解,否则答案为n/lst-1
}
int main(){
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
solve();
return 0;
}