随笔分类 - 数论
摘要:这里贴一下勾股数的构造: 当a为大于1的奇数2n+1时,b=2n2+2n, c=2n2+2n+1。 实际上就是把a的平方数拆成两个连续自然数,例如: n=1时(a,b,c)=(3,4,5) n=2时(a,b,c)=(5,12,13) n=3时(a,b,c)=(7,24,25) 当a为大于2的偶数2n
阅读全文
摘要:给你一个n个初始元素都为1的序列和m个询问q。 询问格式为:l r x(x为2or3) 最后求1~n所有数的GCD GCD:把每个数分别分解质因数,再把各数中的全部 公有质因数 提取出来连乘,所得的积就是这几个数的最大公约数。 include include include include incl
阅读全文
摘要:``` include include include include include include include include include include include include include include include include include include de
阅读全文
摘要:a[i]=a[i 1]+b[i 1]+1, b[i]=2 a[i 1] 5 ; a[1]=1,b[1]=1, 问a[x]=?,b[x]=? 很简单的递推,一步步推即可,但是,如果x是10^9,如何推? 思维:递推式可以化为矩阵乘积 那么,矩阵A[i]=A[i 1] B; A[i+1]=A[i] B=
阅读全文
摘要:康托展开(有关全排列) 康托展开:已知一个排列,求这个排列在全排列中是第几个 康托展开逆运算:已知在全排列中排第几,求这个排列 定义: X=an (n 1)!+an 1 (n 2)!+...+ai (i 1)!+...+a2 1!+a1 0! ai为整数,并且0康托展开有啥用呢? 维基:n位(0~n
阅读全文
摘要:【链接】: "CF" 【题意】:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价。 【分析】:分情况讨论,自己多举几个栗子。 【代码】: include include include include include include include include inc
阅读全文
摘要:【链接】: "CF" 【题意】:n组样例,对于每组样例,给你三个数p q b,问你p/q在b进制下是不是一个有限小数,是的话输出Finite,否则输出Infinite。 【分析】:b的过程是对q约分,那么只要b包含q全部的因子即可。考虑1/q,一定是一个小于等于1的数,考虑将小数转化为b进制的过程,
阅读全文
摘要:【链接】: "CF" 【题意】:从一堆数中选一个最大子集,使得任意两个数相减的绝对值都是2的幂。 【分析】:首先很难的一点,需要想到子集最多只能有三个,四个及以上的子集一定不存在(可以证明)。当有三个元素时,则必有其中两对元素之差相等。 【代码】: include using namespace s
阅读全文
摘要:【链接】: "CF" 【分析】: 设上车前人数 x ,中途最大人数为 x+max ,最小人数为 x+min (max≥0,min≤0) 可得不等式组 x+max≤w, x+min≥0 整数解个数 为 max(0,w max+min+1) 求出 max,min 即可,有求和~记得long long 【
阅读全文
摘要:Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Inpu
阅读全文
摘要:链接:https://www.nowcoder.com/acm/contest/110/A 来源:牛客网 题目描述 这题要你回答T个询问,给你一个正整数S,若有若干个正整数的和为S,则这若干的数的乘积最大是多少?请输出答案除以2000000000000000003(共有17 个零) 的余数。 举例来
阅读全文
摘要:链接:https://www.nowcoder.com/acm/contest/121/J来源:牛客网 题目描述 大家知道,黑猫有很多的迷弟迷妹,当然也有相亲相爱的基友,这其中就有一些二五仔是黑猫的小老弟。小老弟是如何产生的呢?聪明的iko告诉黑猫,其实是有规律的(她怎么知道???)! 一开始,有两
阅读全文
摘要:链接:https://www.nowcoder.com/acm/contest/121/F来源:牛客网 题目描述 WWX的女朋友送给了他一个礼物,可是礼物却被一把K进制密码锁锁住了。在礼物盒上还有一张出自她的女朋友的纸条:”嘿嘿~~密码我会在520那天告诉你”。但是WWX想提前知道礼物是什么,所以找
阅读全文
摘要:【出处】: "CF 327 C" include include include include include include include include include using namespace std; define ll long long define mod 100000000
阅读全文
摘要:/* https://blog.csdn.net/fastkeeper/article/details/38905249 https://max.book118.com/html/2017/1007/136303585.shtm 具体数学第一章第二节的问题,Knuth写的 zoj_1652 数论 这
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int maxn = 100000000+100; int n, m, cnt; int f[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
阅读全文
摘要:Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an interesting number, since it is the first odd num
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; int n,k,p[200002],ans; int cnt,c; vector<int> v; void phi() { for(int i=2; i<=n; i++) p[i] = 0; p[1] = 1;
阅读全文
摘要:问n! 转化成k进制后的位数和尾数的0的个数。【UVA 10061 How many zeros and how many digits?】 Given a decimal integer number you will have to find out how many trailing zero
阅读全文
摘要:链接:https://www.nowcoder.com/acm/contest/93/K来源:牛客网 题目描述 wyh学长特别喜欢斐波那契数列,F(0)=0,F(1)=1,F(n)=F(n-1)+F(n-2)(n>=2) 一天他突发奇想,想求F(a^b)%c 输入描述: 输入第一行一个整数T(1<=
阅读全文