CF1028H.Make Square
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We call an array b1,b2,…,bm good, if there exist two indices i<j such that bi⋅bj is a perfect square.
Given an array b1,b2,…,bm , in one action you can perform one of the following:
- multiply any element bi by any prime p ;
- divide any element bi by prime p , if bi is divisible by p .
Let f(b1,b2,…,bm) be the minimum number of actions needed to make the array b good.
You are given an array of n integers a1,a2,…,an and q queries of the form li,ri . For each query output f(ali,ali+1,…,ari) .
输入格式
The first line contains two integers n and q ( 2≤n≤194598 , 1≤q≤1049658 ) — the length of the array and the number of queries.
The second line contains n integers a1,a2,…,an ( 1≤ai≤5032107 ) — the elements of the array.
Each of the next q lines contains two integers li and ri ( 1≤li<ri≤n ) — the parameters of a query.
输出格式
Output q lines — the answers for each query in the order they are given in the input.
输入输出样例
输入#1
10 10 34 37 28 16 44 36 43 50 22 13 1 3 4 8 6 10 9 10 3 10 8 9 5 6 1 4 1 7 2 6
输出#1
2 0 1 3 0 1 1 1 0 0
说明/提示
In the first query of the first sample you can multiply second number by 7 to get 259 and multiply the third one by 37 to get 1036. Then a2⋅a3=268324=5182 .
In the second query subarray is already good because a4⋅a6=242 .
In the third query you can divide 50 by 2 to get 25. Then a6⋅a8=302 .