题库chevron_right分类chevron_right数论
label

数论

73 道题目
简单: 11中等: 30困难: 32

数论 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
204

计数质数

Count all prime numbers less than a given integer n using efficient array and math-based enumeration techniques.

中等
258

各位相加

Add Digits involves repeatedly summing digits of a number until a single digit is obtained.

简单
858

镜面反射

Given a square room with mirrors, find which receptor a laser ray will hit first based on two integers, p and q.

中等
866

回文质数

The Prime Palindrome problem asks for the smallest prime palindrome greater than or equal to a given integer.

中等
914

卡牌分组

Solve the problem of determining if a deck can be partitioned into groups with equal occurrences of card values.

简单
952

按公因数计算最大组件大小

Find the largest connected component in an array where edges exist between numbers sharing a common factor greater than …

困难
1201

丑数 III

Find the nth positive integer divisible by a, b, or c using binary search over the answer space efficiently and accurate…

中等
1250

检查「好数组」

Determine if a given array of positive integers can generate 1 using integer multiples of any subset, leveraging number …

困难
1447

最简分数

Generate simplified fractions between 0 and 1 with denominators up to a given integer n.

中等
1492

n 的第 k 个因子

Find the kth factor of n by scanning divisors carefully or using factor pairs to skip unnecessary checks.

中等
1627

带阈值的图连通性

In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…

困难
1735

生成乘积数组的方案数

Determine the number of arrays of size n where the product equals k using prime factorization and combinatorial DP techn…

困难
1766

互质树

Determine the closest coprime ancestor for each node in a tree using efficient traversal and state tracking of node valu…

困难
1799

N 次操作后的最大分数和

Maximize the score after n operations by selecting pairs from the array and using their GCD with dynamic programming or …

困难
1808

好因子的最大数目

Solve Maximize Number of Nice Divisors by splitting primeFactors into mostly 3s and using fast modular exponentiation.

困难
1819

序列中不同最大公约数的数目

Given an array of positive integers, find the number of different subsequences' GCDs.

困难
1952

三除数

Determine if a given integer has exactly three positive divisors.

简单
1979

找出数组的最大公约数

Find the greatest common divisor of the smallest and largest numbers in an integer array.

简单
1994

好子集的数目

Find the number of good subsets in an integer array, where each subset's product is the product of distinct primes.

困难
1998

数组的最大公因数排序

The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.

困难
2001

可互换矩形的组数

Count all pairs of rectangles that share the exact width-to-height ratio using efficient array scanning and hash lookup.

中等
2183

统计可以被 K 整除的下标对数目

Count Array Pairs Divisible by K requires counting index pairs whose products are divisible by a given number k.

困难
2197

替换数组中的非互质数

Replace Non-Coprime Numbers in Array uses stack-based state management to iteratively merge adjacent non-coprime integer…

困难
2280

表示一个折线图的最少线段数

Determine the fewest lines needed to accurately connect stock price points in a line chart using array and math reasonin…

中等
2338

统计理想数组的数目

This problem involves counting the number of ideal arrays of a given length under certain conditions using state transit…

困难
2344

使数组可以被整除的最少删除次数

Find the minimum number of deletions to make the smallest element in nums divide all elements of numsDivide.

困难
2413

最小偶倍数

Find the smallest even multiple of a given integer using math and number theory concepts efficiently.

简单
2427

公因子的数目

The problem asks to find the number of common factors of two positive integers a and b.

简单
2447

最大公因数等于 K 的子数组数目

Count the number of subarrays with GCD equal to a given value k from a list of integers.

中等
2470

最小公倍数等于 K 的子数组数目

Find the number of subarrays in an array where the least common multiple (LCM) of the subarray equals a given integer k.

中等
2507

使用质因数之和替换后可以取到的最小值

Replace a number with the sum of its prime factors until it stabilizes, and return the smallest value.

中等
2513

最小化两个数组中的最大值

Minimize the Maximum of Two Arrays requires finding the smallest possible maximum number across two arrays, using binary…

中等
2521

数组乘积中的不同质因数数目

Find the number of distinct prime factors in the product of an array of integers.

中等
2523

范围内最接近的两个质数

Find the two closest prime numbers within a given range using efficient number theory techniques and gap comparisons.

中等
2543

判断一个点是否可以到达

Determine if a target point is reachable from (1,1) using math-based moves following number theory rules efficiently.

困难
2584

分割数组使乘积互质

Find the smallest index to split an array so that the products of two parts are coprime using array scanning and hash lo…

困难
2601

质数减法运算

Determine if it's possible to make the array strictly increasing using prime subtractions.

中等
2607

使子数组元素和相等

Solve Make K-Subarray Sums Equal by grouping circular indices with gcd cycles and minimizing each group to its median.

中等
2614

对角线上的质数

Find the largest prime number located on any diagonal of a square matrix using array iteration and prime checking techni…

简单
2654

使数组所有元素变成 1 的最少操作次数

Find the minimum number of operations to transform every element of a positive integer array into 1 using gcd operations…

中等
2709

最大公约数遍历

Determine if every index in an array can be reached from any other using traversals based on greatest common divisors.

困难
2748

美丽下标对的数目

Count all index pairs in an array where the first digit of one number and last digit of another are coprime efficiently.

简单
2761

和等于目标值的质数对

Find all prime number pairs that sum up to a given integer n using an efficient sieve-based array approach.

中等
2807

在链表中插入最大公约数

The problem involves inserting greatest common divisors between adjacent nodes in a linked list.

中等
2818

操作使得分最大

Maximize the score by applying operations on a subarray at most k times, utilizing stack-based state management.

困难
2862

完全子集的最大元素和

Given a 1-indexed array, select a subset where indices' product is a perfect square, then return the maximum sum.

困难
2867

统计树中的合法路径数目

Count Valid Paths in a Tree involves finding paths with exactly one prime number in a tree of n nodes.

困难
2947

统计美丽子字符串 I

Given a string and a value k, count the number of beautiful substrings where vowels * consonants % k == 0.

中等
2949

统计美丽子字符串 II

Count Beautiful Substrings II focuses on finding beautiful substrings with hash tables and number theory techniques.

困难
3012

通过操作使数组长度最小

Minimize the length of an integer array through a series of operations, using a greedy approach with modular arithmetic.

中等
3044

出现频率最高的质数

Find the most frequent prime over 10 from numbers generated by scanning a 2D matrix in all straight directions efficient…

中等
3115

质数的最大距离

Calculate the largest index gap between prime numbers in an array using array traversal and number theory insights effic…

中等
3116

单面值组合的第 K 小金额

Find the kth smallest amount using only one coin denomination at a time, applying binary search efficiently over possibl…

困难
3233

统计不是特殊数字的数字数量

Count the numbers between two integers that are not special, where special numbers are squares of primes.

中等
3260

找出最大的 N 位 K 回文数

Compute the largest n-digit integer divisible by k that forms a palindrome using state transition dynamic programming te…

困难
3312

查询排序后的最大公约数

Solve the Sorted GCD Pair Queries problem by efficiently counting and locating GCDs of all array pairs using hash mappin…

困难
3326

使数组非递减的最少除法操作次数

Determine the minimum number of division operations to make an array non-decreasing using a greedy and invariant-based s…

中等
3334

数组的最大因子得分

Calculate the maximum factor score of an integer array by optionally removing one element using LCM and GCD computations…

中等
3336

最大公约数相等的子序列数量

Count all pairs of non-empty subsequences in an integer array whose elements share the same greatest common divisor effi…

困难
3348

最小可整除数位乘积 II

Find the smallest zero-free number at least as large as num whose digits multiply to a product divisible by t using care…

困难
3377

使两个整数相等的数位操作

Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…

中等
3378

统计最小公倍数图中的连通块数目

Determine the number of connected components in an LCM-based graph using array scanning and hash-based connectivity chec…

困难
3411

最长乘积等价子数组

This problem involves finding the longest subarray where the product equals the LCM multiplied by the GCD, leveraging a …

简单
3444

使数组包含目标值倍数的最少增量

This problem involves incrementing elements of an array to make sure each target element has at least one multiple in th…

困难
3461

判断操作后字符串中的数字是否相等 I

Simulate repeated adjacent digit sums modulo 10 until two digits remain, then check whether those final digits match.

简单
3463

判断操作后字符串中的数字是否相等 II

Determine if repeated digit-sum operations on a numeric string reduce it to two equal digits using math and string techn…

困难
3556

最大质数子字符串之和

Compute the sum of the three largest unique primes from all substrings using hash table plus math efficiently.

中等
3569

分割数组后不同质数的最大数目

Compute the maximum number of distinct prime numbers after sequentially updating array elements with efficient preproces…

困难
3574

最大子数组 GCD 分数

Maximize Subarray GCD Score focuses on maximizing a subarray's score by using at most k doubling operations on an array …

困难
3589

计数质数间隔平衡子数组

Count the number of prime-gap balanced subarrays in an integer array using sliding window techniques and running state u…

中等
3591

检查元素频次是否为质数

Check if any element in the array has a prime frequency count, leveraging array scanning and hash table lookup.

简单
3605

数组的最小稳定性因子

The problem requires finding the minimum stability factor of an array by utilizing binary search and math-based optimiza…

困难
3618

根据质数下标分割数组

Split Array by Prime Indices challenges you to separate elements at prime positions and minimize the absolute sum differ…

中等

关联高频模式

LeetCode 数论题型题解:73题训练路线