@@ -0,0 +1,1691 @@
+//  Copyright 2021 The KeepTry Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A%0Apackage math;%0A%0Apublic class Leetcodewori %7B%0A  // Refer https://en.wikipedia.org/wiki/Modular_exponentiation#Pseudocode%0A  // Assume:%0A  // - (modulus - 1) * (modulus - 1) does not overflow long.MAX_VALUE%0A  // - b * b does not overflow long.MAX_VALUE%0A  // - r * b does not overflow long.MAX_VALUE%0A  // b: 0 %3C base.%0A  // e: 0 %3C= exponent%0A  // m: 0 %3C modulus%0A  long modpow(long b, int e, int m) %7B%0A    if (m == 1) return 0;%0A    if(e==0%7C%7Cb==1) return 1;%0A%0A    b %25= m;%0A%0A    long r = 1;%0A    while (e %3E 0) %7B%0A      if ((e & 1) == 1) r = r * b %25 m;%0A      e = e %3E%3E 1; // so it is O(loge)%0A      b = b * b %25 m;%0A    %7D%0A    return r;%0A  %7D%0A%0A  // O%EF%BC%88logN)%0A  // Refer hint 1-4%0A  public int maxNiceDivisors(int pf) %7B // is the primeFactors%0A    /*%0A    1 %3C= primeFactors %3C= 10%5E9%0A    */%0A    int mod = 1000000007;%0A    // Note%0A    // 2147483647 = Integer.Max_value%0A    //           %3C (1000000007-1)%5E2=1e18%0A    //          %3C Long.Max_value =%0A    // 9,223,372,036,854,775,807%0A    int%5B%5D st = new int%5B%5D %7B0, 1, 2, 3, 4, 6%7D;%0A    return pf %3C 5 ? pf : (int) (modpow(3, pf / 3 - 1, mod) * st%5B3 + pf %25 3%5D %25 mod);%0A  %7D%0A%7D%0A

1808. Maximize Number of Nice Divisors