数论

Revenge of GCD//HDU - 5019//数论

ⅰ亾dé卋堺 提交于 2020-01-17 04:17:52
Revenge of GCD//HDU - 5019//数论 题目 In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more integers (when at least one of them is not zero), is the largest positive integer that divides the numbers without a remainder. —Wikipedia Today, GCD takes revenge on you. You have to figure out the k-th GCD of X and Y. Input The first line contains a single integer T, indicating the number of test cases. Each test case only contains three integers X, Y and K. [Technical Specification]

P1414 又是毕业季(数论)

流过昼夜 提交于 2020-01-16 13:06:20
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 const int N=1e6+10; 6 int c[N]; 7 int main() 8 { 9 int n; 10 cin>>n; 11 int m=0; 12 for(int i=1;i<=n;i++) 13 { 14 int x; 15 cin>>x; 16 m=max(m,x);//记录最大 17 for(int j=1;j*j<=x;j++) 18 { 19 if(x%j==0) 20 { 21 c[j]++; 22 if(j*j!=x)//一下两个 23 { 24 c[x/j]++; 25 } 26 } 27 } 28 } 29 int p=m;//默契值 30 for(int i=1;i<=n;i++)//人数 31 { 32 while(c[p]<i) 33 { 34 p--; 35 } 36 cout<<p<<endl; 37 } 38 return 0; 39 } 具体思想就是求因数,然后统计。 先是把有这个因数的数有多少个统计出来,比如说样例1 2 3 4 ,那么因数1就有4个,2就有2个,3就有1个,4就有1个,所以人数1234的最大默契值分别是4 2 1 1

k-rounding//CodeForces - 858A//数论

你离开我真会死。 提交于 2020-01-16 05:47:24
k-rounding//CodeForces - 858A//数论 题目 For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n. For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the k-rounding of n. Input The only line contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 8). Output Print the k-rounding of n. Examples Input 375 4 Output 30000 Input 10000 1 Output 10000 Input 38101 0 Output 38101 Input

数论一丢丢模板

怎甘沉沦 提交于 2020-01-13 20:13:24
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+7; const ll mod=1e9+7; bool a[maxn];///存放对于i是否是素数的判断 ///试除法 bool priem(ll n) { if(n==1) return false; for(ll i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } ///唉式筛 void ai() { a[1]=false; for(int i=2;i<maxn;i++) a[i]=true; for(int i=2;i<maxn;i++) { if(a[i]) { for(int j=i*2;j<maxn;j+=i)///优化的话就把出书画改成j=i*i a[j]=false; } } } ///线性筛(欧拉筛) void oula(ll N) { bool number[N+1]; ll prime[N+1]; ll i,j,count=0; memset(number,true,sizeof(number)); for(i=2;i<=N;i++) { if(number[i]) prime[count++]=i; for(j=0;j

hrbust 1328

丶灬走出姿态 提交于 2020-01-08 13:19:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 题目链接: hrbust 1328 这是一道数论的题目,求解方法还是挺巧妙的,尽管够基础。 首先要知道的是多个数的最小公倍数究竟怎么求,有一个公式为lcm(a, b, c) = lcm(lcm(a,b),c),这个公式对n个数一样也成立。 还有一种求法,是将这多个数均写成素数因子的幂相乘的形式(唯一分解定理),然后对每个素数因子,只取最大的指数,相乘就是最小公倍数了。 这里用的是第二种想法,其实这种想法也是够直观,最接近直觉的。如果A(n)和A(n-1)是相等的,那么说明n的素数因子幂相乘的形式中,没有一个素数因子的幂是大于A(n-1)对应素数的幂的。 而如果n含有两个及以上素数因子,比如(a^x)*(b^y),那x和y均不会超过A(n-1)对应素数的幂,因为a^x和b^y都是小于n的,A(n-1)中a和b的指数一定大于等于x和y。如果n可以写成a^x这种形式,那么在A(n-1)的a因子的指数一定不会超过x,因为这么大的指数是第一次出现的(特别地,当x为1时,n为素数)。 #include <cstdio> #include <vector> #include <iostream> using namespace std; vector<int> primes; int not_prime[1010]; int

狄利克雷卷积与莫比乌斯反演

社会主义新天地 提交于 2020-01-04 21:05:21
数论函数 在数论上,算术函数(或称数论函数)指定义域为正整数、陪域为复数的函数,每个算术函数都可视为复数的序列。 最重要的算术函数是积性及加性函数。算术函数的最重要操作为狄利克雷卷积,对于算术函数集,以它为乘法,一般函数加法为加法,可以得到一个阿贝尔环。 ---百度百科 $ \mathbf{f}(x),x \in \mathbb{Z_+}, \mathbf{f}(x)\in C$ 就是定义域为正整数,值域是一个数集 定义数论函数运算: 两个数论函数相等,即他们的每一项都相等 加法: \((\mathbf{f}+\mathbf{g})(i) = \mathbf{f}(i)+\mathbf{g}(i)\) 数乘: \((x\mathbf{f})(i)=x\cdot \mathbf{f}(i)\) 狄利克雷卷积 狄利克雷乘积(Dirichlet product)亦称狄利克雷卷积、卷积,是数论函数的重要运算之一。设f(n)、g(n)是两个数论函数,它们的Dirichlet(狄利克雷)乘积也是一个数论函数,简记为h(n)=f(n)*g(n)。 ---百度百科 定义两个数论函数的狄利克雷卷积符号: \(\ast\) 令 \(\mathbf{t}=\mathbf{f}\ast \mathbf{g}\) 则 \(\mathbf{t}(n) = \sum\limits _{ij=n} \mathbf

P2415 集合求和(数论,洛谷,java)(不指定输入 while(in.hasNext()) )

自闭症网瘾萝莉.ら 提交于 2020-01-01 22:20:14
洛谷链接:https://www.luogu.com.cn/problemnew/solution/P2415 import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int [ ] a = new int [ 31 ] ; long sum = 0 ; int i = 0 ; //不指定输入i个元素 while ( in . hasNext ( ) ) { a [ i ] = in . nextInt ( ) ; sum += a [ i ] ; i ++ ; } //定律:所有子集的和 等于元素和 乘以 2的i-1次方 sum *= Math . pow ( 2 , i - 1 ) ; System . out . println ( sum ) ; } 来源: CSDN 作者: Pluto的小黄鸭 链接: https://blog.csdn.net/weixin_44685629/article/details/103796187

数论——整数分解

白昼怎懂夜的黑 提交于 2019-12-23 08:51:35
积性函数: 函数f如果满足对于任意两个互质的正整数m和n,均有f(mn)=f(m)f(n),就称f为积性函数(或乘性函数)。如果对于任意两个正整数m和n,均有f(mn)=f(m)f(n),就称为完全积性函数。 因数和函数: 费马小定理应用 因数和函数为积性函数,结合费马小定理 试除法 # include <iostream> # include <cmath> using namespace std ; void primeFactor ( int n ) { //求解n的素因数 while ( n % 2 == 0 ) { cout << 2 << " " ; n / = 2 ; } for ( int i = 3 ; i <= sqrt ( n * 1.0 ) ; i + = 2 ) { while ( n % i == 0 ) { cout << i << " " ; n / = i ; } } if ( n > 2 ) { cout << n ; } cout << endl ; } int main ( ) { int n ; cin >> n ; primeFactor ( n ) ; return 0 ; } 筛选法(试除plus) 就是在试除的基础上限定处理范围,提前限定打表减少无关数据 int prime [ N ] ; /// 存储素数 int nprime ;

hdu2620 Ice Rain(数论分块)

北慕城南 提交于 2019-12-22 14:23:59
题意: G i v e n t w o i n t e g e r s n , k ( 1 < = n , k < = 109 ) . Given \ two \ integers\ n, k(1 <= n, k <= 109). G i v e n t w o i n t e g e r s n , k ( 1 < = n , k < = 1 0 9 ) . ,求 思路:数论分块。 ∑ i = 1 n k % i \sum_{i=1}^nk \% i ∑ i = 1 n ​ k % i = ∑ i = 1 n ( k − ⌊ k i ⌋ ∗ i ) =\sum_{i=1}^{n}(k - \left\lfloor\\\tfrac{k}{i}\right\rfloor*i) = ∑ i = 1 n ​ ( k − ⌊ i k ​ ⌋ ∗ i ) = n ∗ k − ∑ i = 1 n ( ⌊ k i ⌋ ∗ i ) =n*k-\sum_{i=1}^{n}(\left\lfloor\\\tfrac{k}{i}\right\rfloor*i) = n ∗ k − ∑ i = 1 n ​ ( ⌊ i k ​ ⌋ ∗ i ) 有数论分块可得, 对于每一个 l l l ,有一个对应的右端点 n ⌊ n l ⌋ \dfrac{n}{\left\lfloor\\\tfrac{n}{l}

数论中的互质数的最大不能组合数

你说的曾经没有我的故事 提交于 2019-12-20 04:28:02
题意:给定A和B,A和B互质,求最大不能组合数,和不能组合数的个数。 基础知识: Gcd(A, B) = 1 → Lcm(A, B) = AB 剩余类,把所有整数划分成m个等价类,每个等价类由相互同余的整数组成 任何数分成m个剩余类,分别为 mk,mk+1,mk+2,……,mk+(m-1) 分别记为{0(mod m)},{1(mod m)}…… 而n的倍数肯定分布在这m个剩余类中 因为Gcd(m,n)=1,所以每个剩余类中都有一些数是n的倍数,并且是平均分配它的旁证,可见HDOJ 1222 Wolf and Rabbit 设 kmin = min{ k | nk ∈ {i (mod m)} }, i ∈ [0, m) 则 nkmin 是{i (mod m)}中n的最小倍数。特别的,nm ∈ {0 (mod m)} nkmin 是个标志,它表明{i (mod m)}中nkmin 后面所有数,即nkmin + jm必定都能被组合出来 那也说明最大不能组合数必定小于nkmin 我们开始寻找max{ nkmin } Lcm(m, n) = mn,所以很明显(m-1)n是最大的 因为(m-1)n是nkmin 中的最大值,所以在剩下的m-1个剩余类中,必定有比它小并且能被m和n组合,这些数就是(m-1)n -1,(m-1)n -2,……,(m-1)n -(m-1) 所以最大不能被组合数就是(m