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. Ubuntu1804 源码阅读神器,egypt+graphviz 图形化显示函数调用关系(超详细+图文并茂)

    函数调用图可以让我们更加直观地了解到源码函数直接的调用和层次关系,提高阅读源码的效率,工欲善其事,必先利其器: 文章目录 1 前言 2 graphviz 安装 3 egypt 安装 4 测试 5 结论 ...

  2. [hdu5226]组合数求和取模(Lucas定理)

    题意:给一个矩阵a,a[i][j] = C[i][j](i>=j) or 0(i < j),求(x1,y1),(x2,y2)这个子矩阵里面的所有数的和. 思路:首先问题可以转化为求(0,0 ...

  3. 关于jquery样式切换的一些想法

    前一阵子写了一些代码,都是关于一个按钮点击切换状态的按钮,当时没有想周到就用addClass removeClass来控制这个控件的状态,后来想想觉得不妥. <html> <head ...

  4. 初识spring boot maven管理--使用spring-boot-starter-parent

    springboot官方推荐我们使用spring-boot-starter-parent,spring-boot-starter-parent包含了以下信息: 1.使用java6编译级别 2.使用ut ...

  5. C# Sign In With Apple苹果登陆后端验证

    苹果App授权登录 苹果官方的授权文档: 生成Token:https://developer.apple.com/documentation/sign_in_with_apple/generate_a ...

  6. webpack 3 升级 webpack4 个人笔记

    参考文章: 1. webpack4升级完全指南 https://segmentfault.com/a/1190000014247030 2. Mobx useStrict is not a funct ...

  7. Request.params,Request.form,Request.querystring区别(转)

    自己总结:---大致意思是: 1.传参的方式分为:get方式传参,post方式传参,request.cookies和request.servervariables 2.这几种获取参数方式获取的都是一个 ...

  8. mouseover与mouseenter区别

    学习笔记. mouseover:在鼠标移入元素本身或者子元素时都会触发事件,相当于有一个冒泡过程.而且在鼠标移入子元素中时,父元素会显示离开的状态:相应的,当鼠标从子元素移入父元素,子元素也会显示离开 ...

  9. poj3680 最大权不相交路径

    Intervals Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 8587   Accepted: 3662 Descrip ...

  10. vue脚手架3.0的安装与使用

    一.安装 1.先检查是否有安装vue  (vue-cli3需要node大于等于8.9版本) //vue -V 2.如果没安装跳过.安装有3.0以下的版本就的先卸载掉以前的版本 npm uninstal ...