![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数论
文章平均质量分 75
Guapifang
这个作者很懒,什么都没留下…
展开
-
Leetcode754. 到达终点数字 --数论+思维
你可以做一些数量的移动 numMoves :每次你可以选择向左或向右移动。第 i 次移动(从 i == 1 开始,到 i == numMoves ),在选择的方向上走 i 步。给定整数 target ,返回 到达目标所需的 最小 移动次数(即最小 numMoves )。示例 1:输入: target = 2输出: 3解释:第一次移动,从 0 到 1。第二次移动,从 1 到 -1。第三次移动,从 -1 到 2。示例 2:输入: target = 3输出: 2。原创 2022-11-04 19:54:14 · 985 阅读 · 0 评论 -
LeetCode 483. 最小好进制--数学分析+二分
最小好进制对于给定的整数 n, 如果n的k(k>=2)进制数的所有数位全为1,则称 k(k>=2)是 n 的一个好进制。以字符串的形式给出 n, 以字符串的形式返回 n 的最小好进制。示例 1:输入:“13”输出:“3”解释:13 的 3 进制是 111。示例 2:输入:“4681”输出:“8”解释:4681 的 8 进制是 11111。示例 3:输入:“1000000000000000000”输出:“999999999999999999”解释:100000000.原创 2020-12-06 13:58:33 · 331 阅读 · 0 评论 -
LeetCode 793. 阶乘函数后K个零--找数据规律+二分
阶乘函数后K个零f(x) 是 x! 末尾是0的数量。(回想一下 x! = 1 * 2 * 3 * … * x,且0! = 1)例如, f(3) = 0 ,因为3! = 6的末尾没有0;而 f(11) = 2 ,因为11!= 39916800末端有2个0。给定 K,找出多少个非负整数x ,有 f(x) = K 的性质。示例 1:输入:K = 0输出:5解释: 0!, 1!, 2!, 3!, and 4! 均符合 K = 0 的条件。示例 2:输入:K = 5输出:0解释:没有匹配到这样.原创 2020-12-01 21:28:25 · 229 阅读 · 0 评论 -
LeetCode 1015. 可被 K 整除的最小整数--数学证明+取模运算
可被 K 整除的最小整数给定正整数 K,你需要找出可以被 K 整除的、仅包含数字 1 的最小正整数 N。返回 N 的长度。如果不存在这样的 N,就返回 -1。示例 1:输入:1输出:1解释:最小的答案是 N = 1,其长度为 1。示例 2:输入:2输出:-1解释:不存在可被 2 整除的正整数 N 。示例 3:输入:3输出:3解释:最小的答案是 N = 111,其长度为 3。提示:1 <= K <= 10^5题解:先处理一个问题,题目是要求找111…类型的.原创 2020-10-28 13:17:36 · 490 阅读 · 0 评论 -
LeetCode 1073. 负二进制数相加---模仿普通的二进制数运算
负二进制数相加给出基数为 -2 的两个数 arr1 和 arr2,返回两数相加的结果。数字以 数组形式 给出:数组由若干 0 和 1 组成,按最高有效位到最低有效位的顺序排列。例如,arr = [1,1,0,1] 表示数字 (-2)^3 + (-2)^2 + (-2)^0 = -3。数组形式 的数字也同样不含前导零:以 arr 为例,这意味着要么 arr == [0],要么 arr[0] == 1。返回相同表示形式的 arr1 和 arr2 相加的结果。两数的表示形式为:不含前导零、由若干 0 和.原创 2020-10-21 20:13:49 · 490 阅读 · 0 评论 -
LeetCode 1590. 使数组和能被 P 整除---前缀取模进行位置标记
使数组和能被 P 整除给你一个正整数数组 nums,请你移除 最短 子数组(可以为 空),使得剩余元素的 和 能被 p 整除。 不允许 将整个数组都移除。请你返回你需要移除的最短子数组的长度,如果无法满足题目要求,返回 -1 。子数组 定义为原数组中连续的一组元素。示例 1:输入:nums = [3,1,4,2], p = 6输出:1解释:nums 中元素和为 10,不能被 p 整除。我们可以移除子数组 [4] ,剩余元素的和为 6 。示例 2:输入:nums = [6,3,5,2],.原创 2020-09-21 10:32:15 · 379 阅读 · 0 评论 -
LeetCode 523. Continuous Subarray Sum--数论
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple of k, that is, sums up to n*k where n is also an integer.Example 1:Input: [23, 2,原创 2020-09-11 19:46:20 · 134 阅读 · 0 评论 -
PAT甲级 1059 Prime Factors (25分) 素数筛
**1059 Prime Factors (25分)**Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1k1×p2k2×⋯×pmkm.Input Specification:Each input file contains one test case which原创 2020-08-15 22:06:13 · 85 阅读 · 0 评论 -
PAT甲级 1049 Counting Ones (30分)--数论,根据数据性质找规律
1049 Counting Ones (30分)The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in 1, 10, 11, and 12.Input Spec原创 2020-08-13 23:55:01 · 139 阅读 · 0 评论 -
牛客网2018
链接:https://ac.nowcoder.com/acm/contest/1107/K来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536KSpecial Judge, 64bit IO Format: %lld题目描述Given a, b, c, d, find out the number of pairs of integ...原创 2019-10-02 19:41:19 · 143 阅读 · 1 评论 -
洛谷P3414 SAC#1 - 组合数
题目背景本题由世界上最蒟蒻最辣鸡最撒比的SOL提供。寂月城网站是完美信息教室的官网。地址:http://191.101.11.174/mgzd 。题目描述辣鸡蒟蒻SOL是一个傻逼,他居然觉得数很萌!今天他萌上了组合数。现在他很想知道sigma(C(n,i))是多少;其中C是组合数(即C(n,i)表示n个物品无顺序选取i个的方案数),i取从0到n所有偶数。由于答案可能很大,请输出答案对6...原创 2019-08-17 23:07:12 · 242 阅读 · 0 评论 -
Leading and Trailing--巧用对数进行数据拆分
You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.InputInput starts with an integer T (≤ 1000), denoting the numbe...原创 2019-08-07 11:52:56 · 598 阅读 · 0 评论 -
2019牛客网暑期多校赛第七场B题--Irreducible Polynomial--多项式可分解判别
链接:https://ac.nowcoder.com/acm/contest/887/B来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld题目描述In mathematics, a polynomial is an expression consisting of variables (...原创 2019-08-09 12:20:26 · 195 阅读 · 0 评论 -
Aladdin and the Flying Carpet--唯一分解定律
It’s said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.Aladdin was about to enter to a magic...原创 2019-08-07 10:09:05 · 171 阅读 · 0 评论 -
Happy 2006--数论gcd
Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9…are all relatively prime to 2006.Now your job is easy: for the ...原创 2019-07-26 23:39:16 · 119 阅读 · 0 评论