ICode9

精准搜索请尝试: 精确搜索
  • 1716. Sum of Different Primes2021-02-19 10:29:04

    1716. Sum of Different Primes 单点时限: 5.0 sec 内存限制: 256 MB A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k, you should count the number of ways to express

  • poj2154(Polya+欧拉函数优化模版)2021-02-18 10:29:32

    #include <cstdio> #include <cstring> #include<iostream> using namespace std; const int maxx=45000; int p; int vis[maxx]; bool primes[maxx]; int k=0; void prime(){//素数筛 int i,j; memset(primes,true,sizeof(primes)); for(i=2;i<

  • Acwing---874. 筛法求欧拉函数 (Java)_分解质因数模板2021-02-16 19:31:53

    874. 筛法求欧拉函数 ①. 题目②. 思路③. 学习点④. 代码实现 原题链接 ①. 题目 ②. 思路 欧拉函数是一个 积性函数 就是说 m,n互素 则 φ(mn)=φ(m)∗φ(n) ①若该数是质数p的话,那么该数的欧拉函数就是p−1。② 筛法利用的原理是 任意整数 x 的倍数 2x,3x,… 等

  • 美味果冻2021-02-12 13:31:07

    链接:https://ac.nowcoder.com/acm/problem/50418 来源:牛客网 题目描述 \sum_{i=1}{n}{}\sum_{j=1}{i}{i*\left[ \frac{i}{j}\right]^{j}}∑ i=1 n ​ ∑ j=1 i ​ i∗[ j i ​ ] j 由于n越大jelly越美味,这里n<=3000000,只需求这个式子对1e9+7取模的值。 输入描述: 第一行

  • 1015 Reversible Primes2021-02-08 13:57:30

    1015 Reversible Primes A reversible prime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given any two positi

  • 数论题目整理(持续补充)2021-02-07 20:59:33

    数论错题整理 1、最大的不能被表示成素数幂的数+最小公倍数求法 题目链接 对于2,不止有因子2还有其他素数因子,能达到的最大数为 3 ∗ 2 k

  • codeforces 1445 C Division (质因数分解)2021-02-05 12:57:03

    题面 题意 t组样例,每组给定一个p,q 找到一个最大的x,满足 p%x==0 && x%q !=0 题解 对于p%q != 0 那么 x 最大就是 p对于p%q ==0 ,我们就可以将 x=p 变小,来满足条件,因为要满足条件1,所以x变小的只能是p的因子倍,要满足条件2,而且要最大,(q,p共有的因子)我们只需要将x的因子幂减少

  • 1015 Reversible Primes (20分)2021-01-05 09:32:05

    我丢,又读假题了。。。理解成十进制系统下的质数判断了 看到系统,不免想起被离散支配的恐惧+_+ 题意 给定两个整数 \(N\) 和 \(D\),如果 \(N\) 是一个质数,并且将 \(N\) 转化为 \(D\) 进制表示后,再进行反转,得到的新数字转化为十进制表示后如果也是一个质数,则称 \(N\) 在 \(D\) 进制系

  • 基础数论--容斥定理2020-12-19 17:35:33

    在计数时,必须注意没有重复,没有遗漏。为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无重复,这种计数的方法称为容斥原理

  • POJ.2689-Prime Distance(二次筛法+思维)2020-12-12 21:33:53

    Language:DefaultPrime Distance Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 32911Accepted: 8353DescriptionThe branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number

  • leetcode刷题笔记313题 超级丑数2020-12-04 20:03:17

    leetcode刷题笔记313题 超级丑数 源地址:313. 超级丑数 问题描述: 编写一段程序来查找第 n 个超级丑数。 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数。 示例: 输入: n = 12, primes = [2,7,13,19] 输出: 32 解释: 给定长度为 4 的质数列表 primes = [2,7,

  • C++ 204. 计数质数-数据更新方向解释2020-12-03 14:59:05

    204. 计数质数 统计所有小于非负整数 n 的质数的数量。 示例 1: 输入:n = 10 输出:4 解释:小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。 示例 2: 输入:n = 0 输出:0 示例 3: 输入:n = 1 输出:0 提示: 0 <= n <= 5 * 106 题解: 方法一:枚举 由于最多有

  • 求0到n之间素数个数的序列2020-11-09 18:01:38

    要求: (1) 找出0-1000之间素数(2) 设f(n)表示0-n之间的素数个数,计算出当n=0,1,2,3,.....,997时f(n)的值,并写入文件 分析:   首先找素数使用一个效率较高的方法——Eratosthenes筛法,只要把1和不超过1000的正合数都删去。其原理为:由于正合数必有不可约数是小于等于其平方根的,只要首

  • 核桃的数量2020-10-03 10:32:45

    再将unordered_map改成map,把auto遍历改成迭代器遍历后,通过。 #include<iostream> #include<map> using namespace std; int a, b, c; map<int, int> primes; void get(int x){ for(int i = 2; i <= x / i; i ++){ if(x % i == 0){ int cnt =

  • 20.求组合数 IV2020-08-19 14:01:24

     这种求组合数问题是要把最终答案算出来,而不是把最终答案模上一个数 就是直接用定义求组合数,分解质因数,然后用上高精度乘法 还是要吐槽一句python自带高精,python大法好,之后还要转python,酸了酸了 如何求a!中有多少个质因子p呢  一直乘到p的若干次方比a大了为止,这步操作时间复杂

  • 1015 Reversible Primes2020-06-24 18:02:01

    A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given any two positive integers N (&

  • 204.Count Primes2020-05-11 17:08:33

    给定一个正整数,求小于这个数的质数个数。Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. 思路:一、暴力,利用for循环,对 2~n的数遍历,当遇到质数时,将其加入动态数组中,内一次对动态数组的质数求模,若这个数是质数,则加入动态数组。第一次

  • 面试题49. 丑数2020-05-09 18:59:09

    题目:     解答: 方法一:优先级队列 1 class Solution { 2 public int nthUglyNumber(int n) { 3 PriorityQueue<Long> pq = new PriorityQueue<>(); 4 Set<Long> s = new HashSet<>(); 5 //初始化,放进堆和set,发现1要开Long数组才可以 6

  • LeetCode 313. 超级丑数(动态规划)2020-05-07 18:03:03

    1. 题目 编写一段程序来查找第 n 个超级丑数。 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数。 示例: 输入: n = 12, primes = [2,7,13,19] 输出: 32 解释: 给定长度为 4 的质数列表 primes = [2,7,13,19], 前 12 个超级丑数序列为:[1,2,4,7,8,13,14,

  • 质因数分解 120=2的3次方*3的一次方*5的一次方2020-04-22 15:54:07

    void get_primes(int n) { for(int i=2;i<=sqrt(n);i++) { if(n%i==0)//如果可以整除 { prime[++m]=i;//就加入 c[m]=0;//初始化一下 while(n%i==0) n/=i,c[m]++;//循环一下,n能除以多少个i } } if(n>1)//到最后的时候 再加进

  • 蓝桥杯 素数求和 筛素数2020-04-20 20:52:08

    问题描述   输入一个自然数n,求小于等于n的素数之和 样例输入 2 样例输出 2 数据规模和约定   测试样例保证 2 <= n <= 2,000,000 数论知识,线性筛。 待复习。 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 2000010; 4 int primes[N], cnt; 5 boo

  • 求约数2020-04-17 20:02:23

    试除法求约数: #include <iostream> #include <algorithm> #include <vector> using namespace std; int n; vector<int> get_divisors(int x) { vector<int> res; for(int i = 1;i <= x / i; i++) { if(x % i == 0)

  • 最大公约数(gcd为素数的数对个数2020-04-05 17:54:11

    # 题意 给定一个数n,求出 1 ≤ x,y ≤ n ,gcd(x,y)为质数 数据范围: 1 ≤ n ≤ 107  # 题解     gcd(x,y)=p =>gcd(x/p,y/p)=1 x'=x/p,y'=y/p 即转化为了在1 ≤ x',y' ≤ n/p 中互质的个数和 x和y代表不同,所以对于(x1,y1),(x2,y2),x1=y2,y1=x2,是不同的。 预处理欧拉函数的前缀和

  • 樱花(阶乘约数个数2020-04-03 22:05:40

    # 题意 给定一个整数n,求有多少个x,y 满足1/x+1/y=1/n! n ∈ [1,1e6] # 题解     1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N=1e6+10,mod=1e9+7; 5 int n; 6 int p[N],cnt; 7 bool st[N]; 8 void get_primes(int n){ 9

  • M - Help Hanzo LightOJ - 1197 (大区间素数筛法)2020-03-30 21:51:39

    题解:素数区间问题。注意到a和b的范围是1<<31,所以直接暴力打表肯定不可以。如果一个数是合数,他的两个因子要么是两个sqrt(x),要么就分布在sqrt(x)两端,所以我们可以根据sqrt(n)之前的数来把sqrt(n)之后的素数给筛出来。 首先进行1e6的素数打表。然后对每个l,r,首先找到第一个大于等于l

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有