题解:P9179 [COCI 2022/2023 #5] Logaritam
题目传送门
题意
给定一个长度为
然后有
思路
由于
当
单次查询时间复杂度为
AC CODE
::::success[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;
}
::::