372. 超级次方

你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出。

示例 1:

输入: a = 2, b = [3]

输出: 8

示例 2:

输入: a = 2, b = [1,0]

输出: 1024

PS:

我现在饱受数学的折磨,欧拉筛,欧拉函数,

(((φ(◎ロ◎;)φ)))

class Solution {
//372超级次方
public int superPow(int a ,int[] b){
int c = 1337;
int exp = 0;
int phi = euler(c);
//同余
for(int i=0;i<b.length;i++) exp = (exp*10+b[i])%1140; return qucikPow(a%1337,exp,1337);
}
//快速幂计算
public int qucikPow(int a,int b,int c){
int ans =1;
while(b>0){
if((b&1)==1){
ans = (ans*a)%c;
}
b >>=1;
a = (a*a)%c;
}
return ans;
}
//欧拉函数
public int euler(int n){
int ret= n;
for(int i=2;i*i<n;i++){
if(n%i==0){//n的质因数
ret = ret/n*(n-1); //欧拉函数公式
while(n%i==0){//去掉质因数i
n/=i;
}
}
}
if(n>1){//n本来就是质数 f(n) = n-1;
ret = ret/n*(n-1);
}
return ret;
} }

Java实现 LeetCode 372 超级次方的更多相关文章

  1. C#版(击败100.00%的提交) - Leetcode 372. 超级次方 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. Leetcod ...

  2. Leetcode 372.超级次方

    超级次方 你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出. 示例 1: 输入: a = 2, b = [3] 输出: 8 示例 2: 输入: a ...

  3. Java实现 LeetCode 517 超级洗衣机

    517. 超级洗衣机 假设有 n 台超级洗衣机放在同一排上.开始的时候,每台洗衣机内可能有一定量的衣服,也可能是空的. 在每一步操作中,你可以选择任意 m (1 ≤ m ≤ n) 台洗衣机,与此同时将 ...

  4. Java实现 LeetCode 313 超级丑数

    313. 超级丑数 编写一段程序来查找第 n 个超级丑数. 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数. 示例: 输入: n = 12, primes = [2,7, ...

  5. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  6. Java for LeetCode 214 Shortest Palindrome

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  7. Java for LeetCode 212 Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  8. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

  9. Java for LeetCode 210 Course Schedule II

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

随机推荐

  1. 一文教你快速搞懂 FOC ramp function 斜坡函数的作用和实现

    文章目录 定义 程序的实现 matlab 程序 C语言程序 定义 x(t)={0,t<0At,t≥0 x(t) = \begin{cases} 0,t<0\\ At,t \ge 0\\ \ ...

  2. 武装你的WEBAPI-OData入门

    本文属于OData系列 目录(可能会有后续修改) 武装你的WEBAPI-OData入门 武装你的WEBAPI-OData便捷查询 武装你的WEBAPI-OData分页查询 武装你的WEBAPI-ODa ...

  3. JS的数据类型判断函数、数组对象结构处理、日期转换函数,浏览器类型判断函数合集

    工具地址:https://github.com/BothEyes1993/bes-jstools bes-jstools 100多个基础常用JS函数和各种数据转换处理集合大全,此工具包是在 outil ...

  4. Centos最小安装

    网络配置 虚拟机安装使用的NAT模式 #enoXXX 为自己的网卡名称, 使用ip addr 可以查看 将/etc/sysconfig/network-scripts/ifcfg-enoXXX中的ON ...

  5. linux-rpm强制安装跳过依赖包

    [root@localhost ~]# rpm -ivh tigervnc-1.10.80-4.20200317git8b4be5fd.el7.x86_64.rpm --nodeps --force ...

  6. loadrunner Error -27985问题

    错误提示:Error -27985: There is no context for HTML-based functions. A previous function may not have us ...

  7. 我们为什么推荐在Json中使用string表示Number属性值?

    在这篇简短的文章中,我将解释在使用JSON传输数据时,为什么浮点数或大十进制值应表示为字符串 . long类型引发的诡异情况 长话短说,同事在利用swagger对接后端API时,诡异的发现swagge ...

  8. 4.1Go if-else

    1. Go if-else Golang程序的流程控制决定程序如何执行,主要有三大流程控制,顺序控制.分支控制.循环控制. 条件语句需要定义一个或多个条件,并且对条件测试的true或false来决定是 ...

  9. logback如何配置springboot框架

    创建logback-spring.xm在src/main/resources下面(springboot推荐使用logback-spring.xml而不是logback.xml)文件. logback- ...

  10. Java的每个Thread都希望拥有自己的名称

    一. 介绍 平时工作中可能会碰到排查多线程的bug,而在排查的时候,如果线程(单个线程或者是线程池的线程)没有一个比较明确的名称,那么在排查的时候就比较头疼,因为排查问题首先需要找出“问题线程”,如果 ...