CF1028H.Make Square
普及/提高-
通过率:0%
时间限制:7.00s
内存限制:1024MB
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).
我们称一个数组 b1,b2,…,bm 是“好的”,如果存在两个下标 i<j,使得 bi⋅bj 是一个完全平方数。
给定一个数组 b1,b2,…,bm,在一次操作中,你可以执行以下两种操作之一:
- 将任意元素 bi 乘以任意一个质数 p;
- 若 bi 能被质数 p 整除,则可将 bi 除以质数 p。
令 f(b1,b2,…,bm) 表示使数组 b 变为“好的”所需的最少操作次数。
现给你一个包含 n 个整数的数组 a1,a2,…,an,以及 q 个形如 li,ri 的查询。对每个查询,请输出 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.
第一行包含两个整数 n 和 q(2≤n≤194598,1≤q≤1049658)—— 分别表示数组的长度和查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤5032107)—— 表示数组的元素。
接下来的 q 行中,每行包含两个整数 li 和 ri(1≤li<ri≤n)—— 表示一次查询的参数。
输出格式
Output q lines — the answers for each query in the order they are given in the input.
输出 q 行——按输入中给出的顺序,依次输出每个查询的答案。
输入输出样例
输入#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.
在第一个样例的第一个查询中,你可以将第二个数乘以 7 得到 259,并将第三个数乘以 37 得到 1036。此时 a2⋅a3=268324=5182。
在第二个查询中,子数组本身已满足条件,因为 a4⋅a6=242。
在第三个查询中,你可以将 50 除以 2 得到 25。此时 a6⋅a8=302。
输入解题思路,AI测评打分。不知道怎么写?