首页 > 其他分享 >Counting Rhyme

Counting Rhyme

时间:2024-06-05 15:33:34浏览次数:15  
标签:10 le 19 18 Rhyme 12 test Counting

题面翻译

给定长度为 \(n\) 的序列 \(a\)。对于 \(1\leq i<j\leq n\),若不存在 \(k\in[1,n]\) 使得 \(a_k\mid a_i\) 且 \(a_k\mid a_j\) 那么 \((i,j)\) 是好的。

求出好的数对数量。\(1\le a_i\le n\leq 10^6\)。

题目描述

You are given an array of integers $ a_1, a_2, \ldots, a_n $ .

A pair of integers $ (i, j) $ , such that $ 1 \le i < j \le n $ , is called good, if there does not exist an integer $ k $ ( $ 1 \le k \le n $ ) such that $ a_i $ is divisible by $ a_k $ and $ a_j $ is divisible by $ a_k $ at the same time.

Please, find the number of good pairs.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 2 \cdot 10^4 $ ). The description of the test cases follows.

The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 10^6 $ ).

The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le n $ ).

It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^6 $ .

输出格式

For each test case, output the number of good pairs.

样例 #1

样例输入 #1

6
4
2 4 4 4
4
2 3 4 4
9
6 8 9 4 6 8 9 4 9
9
7 7 4 4 9 9 6 2 9
18
10 18 18 15 14 4 5 6 8 9 10 12 15 16 18 17 13 11
21
12 19 19 18 18 12 2 18 19 12 12 3 12 12 12 18 19 16 18 19 12

样例输出 #1

0
3
26
26
124
82

提示

In the first test case, there are no good pairs.

In the second test case, here are all the good pairs: $ (1, 2) $ , $ (2, 3) $ , and $ (2, 4) $ .

标签:10,le,19,18,Rhyme,12,test,Counting
From: https://www.cnblogs.com/gutongxing/p/18233143

相关文章

  • 题解:P8267 [USACO22OPEN] Counting Liars B & U208878 晴天
    其实,这个题,只需要最简单的枚举,加上最简单的二分查找即可~\(1\leN\le1000\)?枚举吧~咋枚举?显然,最好状态下Bessie的位置一定是某个\(p_i\),否则差一个就会导致有个奶牛要说谎。所以我们枚举(理论来讲要先去个重,这样快一点,不过貌似数据没有重的~)\(p_i\),每次遍历这帮奶牛看看有......
  • 挑战程序设计竞赛 2.1章习题 poj 3046 Ant Counting
    https://vjudge.net.cn/problem/POJ-3046#author=GPT_zh有一天,贝西在蚂蚁山里探头探脑,看着蚂蚁们来来回回地觅食。她发现很多蚂蚁都是兄弟姐妹,彼此无法区分。她还发现,有时只有一只蚂蚁去觅食,有时几只,有时全部。这就产生了大量不同组合的蚂蚁!有点数学天赋的贝茜开始琢磨起来......
  • [USACO10OCT] Lake Counting S
    传送锚点:https://www.luogu.com.cn/problem/P1596由于近期的降雨,雨水汇集在农民约翰的田地不同的地方。我们用一个\(N\timesM(1\leqN\leq100,1\leqM\leq100)\)的网格图表示。每个网格中有水(W)或是旱地(.)。一个网格与其周围的八个网格相连,而一组相连的网格视为一个水坑。约......
  • CF1884D Counting Rhyme 题解
    题目链接:CF或者洛谷给个莫反题解,讲讲常规套路题目要求满足没有\(a_k\mida_i与a_k\mida_j\)的\((i,j)\)的对数,显然即不存在\(a_k\mid\gcd(a_i,a_j)\)。稍微拓展下,如果不存在整除多个数,那么显然不整除它们的\(\gcd\)即可,因为它们的公因数即为满足的最大数,如果为......
  • C. Permutation Counting
    原题链接题解给定一个数组,你知道怎么计算最终答案吗?设数组大小为\(n\),数组中的最小值为\(x\),大于最小值的个数为\(p\)则\(ans=n*x-(n-1)+p\),\(p\in[0,n-1]\)所以\(x\)越大,\(ans\)越大二分的前置条件有了二分\(x\)遍历数组判断\(k\)能否达到这个\(x\)code#i......
  • 探讨:ARC(Automatic Reference Counting)与手动内存管理的区别及工作原理
    在iOS和macOS开发中,内存管理是一个至关重要的话题。在过去,手动内存管理是一项繁琐且容易出错的任务,而引入了ARC(AutomaticReferenceCounting,自动引用计数)之后,内存管理变得更加简单和安全。本文将详细讨论ARC和手动内存管理之间的区别,并解释ARC的工作原理。1.ARC与手......
  • AGC005D ~K Perm Counting
    Statement:若一个有\(n\)个元素的排列\(P\)满足对于任意\(i(1\len\len)\)都有\(|P_i-i|\nek\),则这个排列是合法的。现给定\(n,k\),问有多少个合法的排列。Solution:神仙题啊。考虑容斥。钦定有\(i\)个位置不满足条件,即满足\(|P_i-i|=k\)。这里有一步......
  • qoj1138 Counting Mushrooms
    交互题。有一个隐藏的01序列\(a\),你只知道\(a\)的长度,并记为\(n\)。保证\(a_1=0\)。你可以执行以下操作:询问一个序列\(b\),满足两两不同且长度在\([2,1000]\)之间。交互库会返回\(\sum[a(b_i)\not=a(b_{i+1})]\)。请在\(226\)次操作内求出\(a\)中\(0\)......
  • Codeforces 954H Path Counting
    令输入的为\(a'\),同时\(a'_0=1\)。对其做一个前缀积\(a_i=\prod\limits_{i=0}^ia'_i\),对于\(i\gen\),认为\(a_i=0\)。那么\(a_i\)就相当于是深度\(i+1\)的点的个数。同时也可以得到根的深度为\(l\)时子树内深度为\(r\)的深度的点数为\(\dfrac{a_{r-......
  • CF1748E Yet Another Array Counting Problem の Solution
    Link有些人还是啥都不会。看到题目应该能想到这是笛卡尔树的性质,因为每一对\((l,r)\)都满足最左端最大值位置相同,所以说明在笛卡尔树上,每一对点的lca相同,说明\(a\)和\(b\)序列的笛卡尔树相同。我们以下标为键,\(a_i\)为值建立大根笛卡尔树,现在题目就转换成在这个树上填......