878. Nth Magical Number Hard

@problem@discussion
#Math#Binary Search



1/**
2 * [878] Nth Magical Number
3 *
4 * A positive integer is magical if it is divisible by either a or b.
5 * Given the three integers n, a, and b, return the n^th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
6 *  
7 * Example 1:
8 * 
9 * Input: n = 1, a = 2, b = 3
10 * Output: 2
11 * 
12 * Example 2:
13 * 
14 * Input: n = 4, a = 2, b = 3
15 * Output: 6
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	1 <= n <= 10^9
21 * 	2 <= a, b <= 4 * 10^4
22 * 
23 */
24pub struct Solution {}
25
26// problem: https://leetcode.com/problems/nth-magical-number/
27// discuss: https://leetcode.com/problems/nth-magical-number/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31impl Solution {
32    pub fn nth_magical_number(n: i32, a: i32, b: i32) -> i32 {
33        0
34    }
35}
36
37// submission codes end
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn test_878() {
45    }
46}
47


Back
© 2025 bowen.ge All Rights Reserved.