File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * 372. Super Pow
3+ * https://leetcode.com/problems/super-pow/
4+ * Difficulty: Medium
5+ *
6+ * Your task is to calculate ab mod 1337 where a is a positive integer and b
7+ * is an extremely large positive integer given in the form of an array.
8+ */
9+
10+ /**
11+ * @param {number } a
12+ * @param {number[] } b
13+ * @return {number }
14+ */
15+ var superPow = function ( a , b ) {
16+ return helper ( BigInt ( a ) , BigInt ( b . join ( '' ) ) , 1337n ) ;
17+ } ;
18+
19+ function helper ( a , b , mod ) {
20+ let r = 1n ;
21+
22+ while ( b > 0n ) {
23+ if ( b % 2n == 1 ) {
24+ r = r * a % mod ;
25+ }
26+ b >>= 1n ;
27+ a = a * a % mod ;
28+ }
29+
30+ return Number ( r ) ;
31+ } ;
Original file line number Diff line number Diff line change 155155350|[ Intersection of Two Arrays II] ( ./0350-intersection-of-two-arrays-ii.js ) |Easy|
156156367|[ Valid Perfect Square] ( ./0367-valid-perfect-square.js ) |Easy|
157157371|[ Sum of Two Integers] ( ./0371-sum-of-two-integers.js ) |Medium|
158+ 372|[ Super Pow] ( ./0372-super-pow.js ) |Medium|
158159374|[ Guess Number Higher or Lower] ( ./0374-guess-number-higher-or-lower.js ) |Medium|
159160383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
160161387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
You can’t perform that action at this time.
0 commit comments