/** * 找出未出现的最小正整数 * @param A * @param n * @date 2016-10-7 * @author shaobn */ public static int findArrayMex(int[] a,int n){ int count = n; int temp = 0; int dir = 1; int num = 0; for(int i = 0;i<count-1;i++){ if(a[i]>a[i+1]){ temp = a[i]; a[i]= a[i
整数的阶:设a和n是互素的正整数,使得a^x=1(mod n)成立的最小的正整数x称为a模n的阶 //求阶模板:A^x=1(mod M),调用GetJie(A,M) //输入:10^10>A,M>1 //输出:无解返回-1,有解返回最小正整数x //复杂度:O(M^(0.5)) long long gcd(long long a,long long b) { ) return a; return gcd(b,a%b); } //欧拉函数:复杂度O(n^(0.5)),返回[1,n-1]中所有和n
题目描述: 给出一个无序的正数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许时间复杂度O(n)的算法,并且只能使用常数级别的空间. public class Solution { /** * @param A: an array of integers * @return: an integer */ public int firstMissingPositive(int[] A) { i
Given a positive integer K, you need find the smallest positive integer N such that N is divisible by K, and N only contains the digit 1. Return the length of N. If there is no such N, return -1. Example 1: Input: 1 Output: 1 Explanation: The smalle
The Balance Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8816 Accepted: 3833 Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin usi