CF1423K.Lonely Numbers

普及/提高-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.

More precisely, two different numbers aa and bb are friends if gcd(a,b)gcd(a,b), agcd(a,b)\frac{a}{gcd(a,b)}, bgcd(a,b)\frac{b}{gcd(a,b)} can form sides of a triangle.

Three numbers aa, bb and cc can form sides of a triangle if a+b>ca + b \gt c, b+c>ab + c \gt a and c+a>bc + a \gt b.

In a group of numbers, a number is lonely if it doesn't have any friends in that group.

Given a group of numbers containing all numbers from 1,2,3,...,n1, 2, 3, ..., n, how many numbers in that group are lonely?

在数字世界中,两个不同的数字是朋友,当且仅当它们既有大量共同点,又各自拥有独特的优点。

更准确地说,两个不同的数字 aa 和 bb 是朋友,当且仅当 gcd(a,b)gcd(a,b)、agcd(a,b)\frac{a}{gcd(a,b)}、bgcd(a,b)\frac{b}{gcd(a,b)} 可以构成一个三角形的三条边。

三个数 aa、bb 和 cc 能构成三角形的三条边,当且仅当满足 a+b>ca + b \gt c、b+c>ab + c \gt a 以及 c+a>bc + a \gt b。

在一个数字集合中,若某个数字在该集合中没有任何朋友,则称其为“孤独的”。

给定一个包含所有从 1,2,3,…,n1, 2, 3, \dots, n 的数字的集合,问该集合中有多少个数字是孤独的?

输入格式

The first line contains a single integer tt (1≤t≤106)(1 \leq t \leq 10^6) - number of test cases.

On next line there are tt numbers, nin_i (1≤ni≤106)(1 \leq n_i \leq 10^6) - meaning that in case ii you should solve for numbers 1,2,3,...,ni1, 2, 3, ..., n_i.

第一行包含一个整数 tt(1≤t≤1061 \leq t \leq 10^6),表示测试用例的数量。

下一行包含 tt 个数字 nin_i(1≤ni≤1061 \leq n_i \leq 10^6),表示在第 ii 个测试用例中,你需要对数字 1,2,3,…,ni1, 2, 3, \dots, n_i 进行求解。

输出格式

For each test case, print the answer on separate lines: number of lonely numbers in group 1,2,3,...,ni1, 2, 3, ..., n_i.

对于每个测试用例,在单独的行上输出答案:第 1,2,3,...,ni1, 2, 3, ..., n_i 组中孤独数的个数。

输入输出样例

  • 输入#1

    3
    1 5 10

    输出#1

    1
    3
    3

说明/提示

For first test case, 11 is the only number and therefore lonely.

For second test case where n=5n=5, numbers 11, 33 and 55 are lonely.

For third test case where n=10n=10, numbers 11, 55 and 77 are lonely.

对于第一个测试用例,11 是唯一的一个数,因此它是孤独的。

对于第二个测试用例(n=5n=5),数字 11、33 和 55 是孤独的。

对于第三个测试用例(n=10n=10),数字 11、55 和 77 是孤独的。

输入解题思路,AI测评打分。不知道怎么写?

首页