Skip to content
We areTOP 1%

Count Array Pairs Divisible by K

HardLeetCodeNumber Theory
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Divisibility by k depends only on gcd(nums[i], k). Because k has few divisors, count how often each gcd value occurs and test pairs of values rather than pairs of indices.

More in Number Theory

Number Theory questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Orac and LCMCodeforcesMedium 1600Solve Orac and LCM on Codeforces (opens in a new tab)
2Ugly Number IIILeetCodeMedium Solve Ugly Number III on LeetCode (opens in a new tab)
3Same GCDsCodeforcesHard 1800Solve Same GCDs on Codeforces (opens in a new tab)
4Check If It Is a Good ArrayLeetCodeHard Solve Check If It Is a Good Array on LeetCode (opens in a new tab)
5K-goodCodeforcesHard 1900Solve K-good on Codeforces (opens in a new tab)
6Strange BeautyCodeforcesHard 1900Solve Strange Beauty on Codeforces (opens in a new tab)
7Number of Different Subsequences GCDsLeetCodeHard Solve Number of Different Subsequences GCDs on LeetCode (opens in a new tab)
8Count Array Pairs Divisible by KLeetCodeHard Solve Count Array Pairs Divisible by K on LeetCode (opens in a new tab)
9The Football SeasonCodeforcesHard 2000Solve The Football Season on Codeforces (opens in a new tab)
10CGCDSSQCodeforcesHard 2000Solve CGCDSSQ on Codeforces (opens in a new tab)
11Two DivisorsCodeforcesHard 2000Solve Two Divisors on Codeforces (opens in a new tab)
12Maximum ValueCodeforcesHard 2100Solve Maximum Value on Codeforces (opens in a new tab)
13The Number of PairsCodeforcesHard 2100Solve The Number of Pairs on Codeforces (opens in a new tab)
14Count PairsCodeforcesHard 2300Solve Count Pairs on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account