当前位置:网站首页>Leetcode 2176. 统计数组中相等且可以被整除的数对
Leetcode 2176. 统计数组中相等且可以被整除的数对
2022-06-12 13:57:00 【我不是萧海哇~~~~】

给你一个下标从 0 开始长度为 n 的整数数组 nums 和一个整数 k ,请你返回满足 0 <= i < j < n ,nums[i] == nums[j] 且 (i * j) 能被 k 整除的数对 (i, j) 的 数目 。
示例 1:
输入:nums = [3,1,2,2,2,1,3], k = 2
输出:4
解释:
总共有 4 对数符合所有要求:
- nums[0] == nums[6] 且 0 * 6 == 0 ,能被 2 整除。
- nums[2] == nums[3] 且 2 * 3 == 6 ,能被 2 整除。
- nums[2] == nums[4] 且 2 * 4 == 8 ,能被 2 整除。
- nums[3] == nums[4] 且 3 * 4 == 12 ,能被 2 整除。
示例 2:
输入:nums = [1,2,3,4], k = 1
输出:0
解释:由于数组中没有重复数值,所以没有数对 (i,j) 符合所有要求。
提示:
- 1 <= nums.length <= 100
- 1 <= nums[i], k <= 100
Code:
class Solution {
public:
int countPairs(vector<int>& nums, int k) {
int res=0;
for(int i=0;i<nums.size();i++)
{
for(int j=i+1;j<nums.size();j++)
{
if(nums[i]==nums[j])
{
if((i*j)%k==0)
{
res++;
}
}
}
}
return res;
}
};
边栏推荐
- Codeforces 1637 C. Andrew and stones - simple thinking
- Brush one question every day /537 Complex multiplication
- 【mysql进阶】查询优化原理与方案(六)
- 浅谈中国程序员为什么要跳槽?
- [MySQL advanced] index classification and index optimization scheme (V)
- 十四周作业
- one × Convolution kernel of 1
- Hash tables, sets, maps, trees, heaps, and graphs
- [video lesson] a full set of tutorials on the design and production of Android studio Internet of things app -- all mastered during the National Day
- 通过loganalyzer展示数据库中的日志
猜你喜欢
![[advanced MySQL] evolution of MySQL index data structure (IV)](/img/eb/e32387b172eb4c3a4152dbc3b0cb8f.png)
[advanced MySQL] evolution of MySQL index data structure (IV)

【mysql进阶】索引分类及索引优化方案(五)

Alibaba cloud development board haas510 connects to the Internet of things platform -- Haas essay solicitation

WinDbg preview debug analysis createtoolhelp32snapshot

公司运营中更注重转化的出价策略,如何实现? —Google sem

Possible solutions to problems after CodeBlocks installation

Display logs in the database through loganalyzer

初学者入门阿里云haas510开板式DTU(2.0版本)--510-AS

阿里云开发板vscode开发环境搭建

List of common ACM knowledge points (to be continued)
随机推荐
SystemC uses SC_ report_ Handler processing log printing
one × Convolution kernel of 1
3. Process concealment under the ring ----- continuous concealment and new opening prevention
After reading the question, you will point to offer 16 Integer power of numeric value
Codeforces 1629 E. grid XOR - simple thinking
Leetcode questions brushing February /1020 Number of enclaves
When the byte jumps, the Chinese 996 is output in the United States
CSDN blog points rule
chrome://tracing Performance analysis artifact
[MySQL advanced] index classification and index optimization scheme (V)
阿里云开发板vscode开发环境搭建
TestEngine with ID ‘junit-vintage‘ failed to discover tests
Codeforces 1637 D. yet another minimization problem - Mathematics, DP
SystemC simulation scheduling mechanism
使用make方法创建slice切片的坑
【活动早知道】LiveVideoStack近期活动一览
Mold and remainder
【SemiDrive源码分析】【X9芯片启动流程】25 - MailBox 核间通信机制介绍(代码分析篇)之 RPMSG-IPCC RTOS & QNX篇
Acwing: topology sequence
Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode