#include <bits/stdc++.h>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define aff(v) for(auto e:v) cout<<e<<" ";cout<<endl;
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define yes(check) cout << (check ? "YES" : "NO") << endl
typedef long long ll;
typedef long double ld;
ll n,q,d;
const ll prime=1e9+7;
const ll prime2=998244353;
const ll prime3=7901;
const ll MOD = 998244353;
ll INF=2e18;
const int NAX=2e6+5;
vector<int> sieve(NAX);
void init(){
for(ll i=2;i<NAX;i++){
if(sieve[i]==0){
for(ll j=i;j<NAX;j+=i){
sieve[j]=i;
}
}
}
}
const int MAX_N = 2e6+5;
const int LOG = 21;
int a[MAX_N];
int m[MAX_N][LOG]; // m[i][j] is minimum among a[i..i+2^j-1]
int bin_log[MAX_N];
int query(int L, int R) { // O(1)
int length = R - L + 1;
int k = bin_log[length];
return max(m[L][k], m[R-(1<<k)+1][k]);
}
void solve(){
cin >> n >> q;
priority_queue<pair<int,int>> pq;
bin_log[1] = 0;
for(int i = 2; i <= n; i++) {
bin_log[i] = bin_log[i/2]+1;
}
for(int i=0;i<n;i++){
int va;
cin >> va;
pq.push({va,-i});
}
int curr=0;
while(!pq.empty()){
pair<int,int> p=pq.top();
pq.pop();
int v=p.first;
if(v==1){
continue;
}
v=v/sieve[v];
curr++;
m[abs(p.second)][0]=curr;
if(v==1){
}else{
pq.push({v,p.second});
}
//debug() << imie(p) imie(curr) imie(sieve[p.first]) imie(indexes);
}
for(int k = 1; k < LOG; k++) {
for(int i = 0; i + (1 << k) - 1 < n; i++) {
m[i][k] = max(m[i][k-1], m[i+(1<<(k-1))][k-1]);
}
}
for(int i=0;i<q;i++){
int l,r;
cin >> l >> r;
l--;r--;
cout << query(l,r)<<"\n";
}
}
int main() {
fastInp;
init();
//debug() << imie(s);
//freopen("grids.in","r",stdin);
//freopen("res.out","w",stdout);
// __gcd <long long> (x, y);
int tc=1;
//debug() << imie(sieve);
//cin >> tc;
//cout << setprecision(10)<<fixed;
while(tc--){
//i++;
//cout <<"Test " << i << ":" << "\n";
solve();
}
return 0;
}
/*
Some insights:
.Binary search
.Graph representation
.Write brute force code
.Change your approach
*/
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGZhc3RJbnAgY2luLnRpZSgwKTsgY291dC50aWUoMCk7IGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiNkZWZpbmUgc2ltIHRlbXBsYXRlIDwgY2xhc3MgYwojZGVmaW5lIHJpcyByZXR1cm4gKiB0aGlzCiNkZWZpbmUgZG9yID4gZGVidWcgJiBvcGVyYXRvciA8PAojZGVmaW5lIGVuaSh4KSBzaW0gPiB0eXBlbmFtZSBcCiAgZW5hYmxlX2lmPHNpemVvZiBkdWQ8Yz4oMCkgeCAxLCBkZWJ1ZyY+Ojp0eXBlIG9wZXJhdG9yPDwoYyBpKSB7CnNpbSA+IHN0cnVjdCByZ2UgeyBjIGIsIGU7IH07CnNpbS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L2RlYnVnKCkgPDwgaW1pZShzaWV2ZSk7CgkvL2NpbiA+PiB0YzsKCS8vY291dCA8PCBzZXRwcmVjaXNpb24oMTApPDxmaXhlZDsKCgl3aGlsZSh0Yy0tKXsKCQkvL2krKzsKCQkvL2NvdXQgPDwiVGVzdCAiIDw8IGkgPDwgIjoiIDw8ICJcbiI7CgkJCgkJc29sdmUoKTsKCQkKCX0KCglyZXR1cm4gMDsKfQoKLyoKICAgU29tZSBpbnNpZ2h0czoKICAgIC5CaW5hcnkgc2VhcmNoCiAgICAuR3JhcGggcmVwcmVzZW50YXRpb24KICAgIC5Xcml0ZSBicnV0ZSBmb3JjZSBjb2RlCiAgICAuQ2hhbmdlIHlvdXIgYXBwcm9hY2gKIAogCiAqLwoK
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:4: error: illegal character: '#'
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
^
Main.java:4: error: class, interface, or enum expected
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
^
Main.java:4: error: class, interface, or enum expected
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
^
Main.java:4: error: class, interface, or enum expected
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
^
Main.java:5: error: illegal character: '#'
#define sim template < class c
^
Main.java:5: error: class, interface, or enum expected
#define sim template < class c
^
Main.java:6: error: illegal character: '#'
#define ris return * this
^
Main.java:7: error: illegal character: '#'
#define dor > debug & operator <<
^
Main.java:8: error: illegal character: '#'
#define eni(x) sim > typename \
^
Main.java:8: error: illegal character: '\'
#define eni(x) sim > typename \
^
Main.java:9: error: > expected
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
^
Main.java:9: error: <identifier> expected
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
^
Main.java:9: error: illegal start of type
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
^
Main.java:10: error: not a statement
sim > struct rge { c b, e; };
^
Main.java:10: error: ';' expected
sim > struct rge { c b, e; };
^
Main.java:10: error: not a statement
sim > struct rge { c b, e; };
^
Main.java:10: error: ';' expected
sim > struct rge { c b, e; };
^
Main.java:11: error: ')' expected
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: not a statement
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: not a statement
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: ';' expected
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: ';' expected
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: illegal start of expression
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: not a statement
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: ';' expected
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: not a statement
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:11: error: ';' expected
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
^
Main.java:12: error: not a statement
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
^
Main.java:12: error: ';' expected
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
^
Main.java:12: error: ';' expected
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
^
Main.java:12: error: illegal start of expression
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
^
Main.java:13: error: '.class' expected
sim > char dud(...);
^
Main.java:13: error: not a statement
sim > char dud(...);
^
Main.java:13: error: illegal start of expression
sim > char dud(...);
^
Main.java:14: error: ';' expected
struct debug {
^
Main.java:15: error: illegal character: '#'
#ifdef LOCAL
^
Main.java:15: error: ';' expected
#ifdef LOCAL
^
Main.java:16: error: ';' expected
~debug() { cerr << endl; }
^
Main.java:16: error: not a statement
~debug() { cerr << endl; }
^
Main.java:17: error: illegal start of expression
eni(!=) cerr << boolalpha << i; ris; }
^
Main.java:17: error: illegal start of expression
eni(!=) cerr << boolalpha << i; ris; }
^
Main.java:17: error: ';' expected
eni(!=) cerr << boolalpha << i; ris; }
^
Main.java:17: error: not a statement
eni(!=) cerr << boolalpha << i; ris; }
^
Main.java:17: error: not a statement
eni(!=) cerr << boolalpha << i; ris; }
^
Main.java:18: error: illegal start of expression
eni(==) ris << range(begin(i), end(i)); }
^
Main.java:18: error: illegal start of expression
eni(==) ris << range(begin(i), end(i)); }
^
Main.java:18: error: ';' expected
eni(==) ris << range(begin(i), end(i)); }
^
Main.java:18: error: not a statement
eni(==) ris << range(begin(i), end(i)); }
^
Main.java:19: error: <identifier> expected
sim, class b dor(pair < b, c > d) {
^
Main.java:19: error: <identifier> expected
sim, class b dor(pair < b, c > d) {
^
Main.java:19: error: '{' expected
sim, class b dor(pair < b, c > d) {
^
Main.java:19: error: <identifier> expected
sim, class b dor(pair < b, c > d) {
^
Main.java:20: error: not a statement
ris << "(" << d.first << ", " << d.second << ")";
^
Main.java:23: error: illegal start of expression
*this << "[";
^
Main.java:23: error: not a statement
*this << "[";
^
Main.java:25: error: illegal start of expression
*this << ", " + 2 * (it == d.b) << *it;
^
Main.java:25: error: illegal start of expression
*this << ", " + 2 * (it == d.b) << *it;
^
Main.java:25: error: not a statement
*this << ", " + 2 * (it == d.b) << *it;
^
Main.java:26: error: not a statement
ris << "]";
^
Main.java:28: error: illegal character: '#'
#else
^
Main.java:29: error: illegal start of type
sim dor(const c&) { ris; }
^
Main.java:29: error: not a statement
sim dor(const c&) { ris; }
^
Main.java:30: error: illegal character: '#'
#endif
^
Main.java:31: error: illegal start of type
};
^
Main.java:32: error: illegal character: '#'
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
^
Main.java:32: error: invalid method declaration; return type required
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
^
Main.java:32: error: illegal start of type
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
^
Main.java:32: error: <identifier> expected
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
^
Main.java:32: error: ';' expected
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
^
Main.java:32: error: illegal character: '#'
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
^
Main.java:33: error: illegal character: '#'
#define aff(v) for(auto e:v) cout<<e<<" ";cout<<endl;
^
Main.java:33: error: <identifier> expected
#define aff(v) for(auto e:v) cout<<e<<" ";cout<<endl;
^
Main.java:33: error: <identifier> expected
#define aff(v) for(auto e:v) cout<<e<<" ";cout<<endl;
^
Main.java:34: error: illegal character: '#'
#define mem1(a) memset(a,-1,sizeof(a))
^
Main.java:34: error: invalid method declaration; return type required
#define mem1(a) memset(a,-1,sizeof(a))
^
Main.java:34: error: <identifier> expected
#define mem1(a) memset(a,-1,sizeof(a))
^
Main.java:34: error: ';' expected
#define mem1(a) memset(a,-1,sizeof(a))
^
Main.java:35: error: illegal character: '#'
#define mem0(a) memset(a,0,sizeof(a))
^
Main.java:36: error: illegal character: '#'
#define all(x) (x).begin(),(x).end()
^
Main.java:37: error: illegal character: '#'
#define sz(x) (int)((x).size())
^
Main.java:37: error: <identifier> expected
#define sz(x) (int)((x).size())
^
Main.java:37: error: <identifier> expected
#define sz(x) (int)((x).size())
^
Main.java:37: error: invalid method declaration; return type required
#define sz(x) (int)((x).size())
^
Main.java:37: error: ';' expected
#define sz(x) (int)((x).size())
^
Main.java:38: error: illegal character: '#'
#define yes(check) cout << (check ? "YES" : "NO") << endl
^
Main.java:39: error: <identifier> expected
typedef long long ll;
^
Main.java:40: error: <identifier> expected
typedef long double ld;
^
Main.java:40: error: <identifier> expected
typedef long double ld;
^
Main.java:42: error: illegal start of type
const ll prime=1e9+7;
^
Main.java:43: error: illegal start of type
const ll prime2=998244353;
^
Main.java:44: error: illegal start of type
const ll prime3=7901;
^
Main.java:46: error: illegal start of type
const ll MOD = 998244353;
^
Main.java:48: error: illegal start of type
const int NAX=2e6+5;
^
Main.java:49: error: <identifier> expected
vector<int> sieve(NAX);
^
Main.java:59: error: illegal start of type
const int MAX_N = 2e6+5;
^
Main.java:60: error: illegal start of type
const int LOG = 21;
^
Main.java:61: error: ']' expected
int a[MAX_N];
^
Main.java:61: error: <identifier> expected
int a[MAX_N];
^
100 errors