![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数学—数论
愈努力俞幸运
这个作者很懒,什么都没留下…
展开
-
10.22
数论,上来是最大公约数与最小公倍数,怎么算最大公约数?两种方法一个是欧几里得算法,一个是stein算法,欧几里得算法: int gcd(int a,int b){ while(b) { int r=a%b; a=b; b=r; } return a;}stein算法:int g原创 2017-10-22 23:51:33 · 135 阅读 · 0 评论 -
推公式、逆元、输入外挂
http://acm.hdu.edu.cn/showproblem.php?pid=6304#include<iostream>#include<cstring>#include<cmath>#include<algorithm>#include<cstdio>#define mo 1000000007using nam...原创 2018-07-24 19:43:39 · 146 阅读 · 0 评论 -
多校 HDU 6313 Hack It——构造
题意:构造一个矩阵,使得不存在这样一个子矩阵,子矩阵的四个角都为1思路:首先用常用的数论构造方法,假设n=5^2,那么矩阵可以写作这种形式:xxxxx xxxxx xxxxx xxxxx xxxxxxxxxx xxxxx xxxxx xxxxx xxxxxxxxxx xxxxx xxxxx xxxxx xxxxxxxxxx xxxxx xxxxx xxxxx xxxxx...原创 2018-07-27 22:17:22 · 208 阅读 · 0 评论 -
保存最大的前20项暴力--Heritage of skywalkert
链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 Heritage of skywalkert时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述skywalkert, the new legend of Beihang U...原创 2018-08-05 16:05:13 · 300 阅读 · 0 评论 -
欧拉函数的性质
定理0:对于质数p,φ(p) = p - 1。注意φ(1)=1.定理一:设m与n是互素的正整数,那么 定理二:当n为奇数时,有。因为2n是偶数,偶数与偶数一定不互素,所以只考虑2n与小于它的奇数互素的情况,则恰好就等于n的欧拉函数值。 定理三:设p是素数,a是一个正整数,那么=(p-1)*P^(a-1);关于这个定理的证明用到容斥:由于表示小于与互素数的正整数个数,...原创 2018-08-14 20:56:25 · 2828 阅读 · 0 评论 -
01分数规划
链接:https://www.nowcoder.com/acm/contest/143/A来源:牛客网 gpa时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288KSpecial Judge, 64bit IO Format: %lld题目描述Kanade selected n courses in the university...原创 2018-08-02 20:37:45 · 105 阅读 · 0 评论 -
01分数规划讲解
【关键字】0/1分数规划、最优比率生成树、最优比率环【背景】根据楼教主的回忆录,他曾经在某一场比赛中秒掉了一道最优比率生成树问题,导致很多人跟风失败,最终悲剧。可见最优比率生成树是多么凶残的东西,但是这个东西只要好好研究半天就可以掌握,相信你在看了我写的这篇总结之后可以像楼教主一般秒掉这类问题。因为网上对于...转载 2018-08-02 20:40:04 · 785 阅读 · 0 评论 -
01分数规划
http://poj.org/problem?id=2976【题目大意】给出n组ai和bi,去掉k个使得a的总和除以b的总和最大。.【思路】也就是取(n-k)个数,最大化平均值,最后公式为d(x)=((ai-x*bi)从大到小排列的前(n-k)个的和不小于0)。//#include<bits/stdc++.h>#include<cstdio>#in...原创 2018-08-02 20:53:26 · 117 阅读 · 0 评论 -
勾股数的规律
原创 2018-08-26 10:40:18 · 225 阅读 · 0 评论 -
费马大定理
http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=812Find IntegerTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 6597...原创 2018-08-26 10:41:30 · 674 阅读 · 0 评论 -
同余常用性质
原创 2018-08-26 11:38:18 · 953 阅读 · 0 评论 -
费马小定理
DreamTime Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 908 Accepted Submission(s): 130Special Judge Problem DescriptionFreshmen freque...原创 2018-08-26 11:44:17 · 539 阅读 · 0 评论 -
又见n/i下取整+分块
链接:https://www.nowcoder.com/acm/contest/158/A来源:牛客网 因数个数和时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述q次询问,每次给一个x,问1到x的因数个数的和。输入描述:第一行一个正整数q ;接下来q行,每行一个...原创 2018-08-26 21:03:09 · 1936 阅读 · 0 评论 -
Codeforces--506--div3--D--求与x相加求与m等于0的y的个数
D. Concatenated MultiplesYou are given an array aa, consisting of nn positive integers.Let's call a concatenation of numbers xx and yy the number that is obtained by writing down numbers xx and yy...原创 2018-08-31 00:48:11 · 235 阅读 · 0 评论 -
ACM-ICPC 2018 南京赛区网络预赛
J题预处理,先打个线性筛,把1到n全都分解质因数,计算贡献,每个次幂为一的质因子贡献*2,次幂为2的质因子不算贡献,有超过2次幂的质因子那么这个数字就可以直接置为0了 #include <set>#include <map>#include <deque>#include <stack>#include <queue>#i...原创 2018-09-05 00:12:34 · 149 阅读 · 0 评论 -
前缀后缀gcd 2017 ccpc女生专场 1003 Coprime Sequence
Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, and the GCD (Greatest Common Divisor) of them is equal to 1. ``Coprime Sequence'' is easy to find b...原创 2018-04-26 18:09:15 · 265 阅读 · 0 评论 -
god is a girl
god is a girl题意:解码。将题目中的样例做差输出,打表可得到1 1 2 5 8 13 21所以是按斐波那契额值解码的,一开始直接算的菲波那切数没有取模,这样的话90左右就会超long long所以数组开了100,交了一发run time,所以得把数组开大,就对斐波那契数取个模就好了#include<bits/stdc++.h>using namespace std;in...原创 2018-05-11 00:19:44 · 380 阅读 · 0 评论 -
10.22
数论,筛素数:bool vis[maxn];int prime[maxn];int prim(int n){memset(vis,0,sizeof(vis));int cnt=0;for(i=2;i{if(!vis[i])prime[cnt++]=i;for(j=0;j{vis[i*prime[j]=1;if(i%prime[j]原创 2017-10-23 00:29:16 · 128 阅读 · 0 评论 -
不互质的中国剩余定理
strange way to express integers#include#include#include#include#includeusing namespace std;typedef long long ll;void gcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b) { d=a; x原创 2018-02-02 15:38:38 · 328 阅读 · 0 评论 -
自然数幂与伯努利数,分数相加
sum of powers题目:已知并且求最小的正数M,使得ak+1,ak···a0都是整数;分母求最小公倍数就可以;注意n^k的系数是C(k+1,1)*b1+(k+1);注意最大公约数为负数的情况,强制转化为正数,用分子保存整个分数的正负性,因为题目要求最小的正数M#include#include#include#include#include#include原创 2018-02-05 19:35:24 · 327 阅读 · 0 评论 -
斯特林求N!的位数
链接:https://www.nowcoder.net/acm/contest/75/A来源:牛客网夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样,所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。#include#include#include#include#include#include#include#include#inclu原创 2018-02-05 19:55:30 · 164 阅读 · 0 评论 -
因子数
More divisorsEverybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is of原创 2018-02-06 19:43:31 · 549 阅读 · 0 评论 -
N阶乘与泰勒展式
链接:https://www.nowcoder.net/acm/contest/78/G来源:牛客网在家好冷! 又多冷呢? 大概是零下e度! 为什么是零下e度呢? 不知道,因为我编不下去了。 求给定一个数n,求出最接近n!/e的整数 输入描述:一行一个整数n1输出描述:一行一个整数,即题目描述中所求,由于这个数字可能很大,我们只需要原创 2018-02-07 20:01:10 · 4298 阅读 · 0 评论 -
任意阶幻方解法及c++实现
任意阶幻方的解法及c++实现 在一个由若干个排列整齐的数组成的正方形中,图中任意一横行、一纵行及对角线的几个数之和都相等,具有这种性质的图表,称为“幻方”。我国古代称为“河图”、“洛书”,又叫“纵横图”。奇数阶幻方(罗伯法)奇数阶幻方最经典的填法是罗伯法。填写的方法是: 把1(或最小的数)放在第一行正中; 按以下规律排列剩下的(n×n-1)个数: ...转载 2018-02-20 19:36:39 · 2207 阅读 · 0 评论 -
时针与分针的夹角的易错点
分针每分钟转360/60=6度;分针每秒钟转6/60=0.1度;时针每小时转360/12=30度;时针每分钟30/60=0.5度;时针每秒钟转0.5/60=1/120度;所以h时m分s秒时针与0刻度线(12时的刻度线)的夹角:30h+0.5m+1/120*s;h时m分s秒分针与0刻度线的夹角:6m+0.1s;时针与分针夹角a:a=|6m+0.1-30h-0.5m-1/120s|;习惯上,超过180...原创 2018-03-20 19:02:22 · 1304 阅读 · 0 评论 -
欧拉函数
hdoj 2588 GCD 【欧拉函数 问题转换】 原创 2015年06月11日 17:38:27 标签: 340编辑 删除 ...转载 2018-04-24 20:45:28 · 141 阅读 · 0 评论 -
费马小定理
hdoj 4704 Sum 【费马小定理 + 快速幂】 原创 2015年09月20日 21:38:30 334 ...原创 2018-04-24 21:02:25 · 229 阅读 · 0 评论 -
Easy Summation 假的自然数幂的和
easy summation题意:就是求自然数幂的和。注意平常求自然数幂的和当然是用伯努利数,但是本题n很大,k很小,用伯努利数来做会内存超限。用快速幂暴力求即可。#include<bits/stdc++.h>using namespace std;typedef long long ll;const int mod=1e9+7;ll powmod(ll a,ll b){ ...原创 2018-05-09 20:18:07 · 123 阅读 · 0 评论 -
Romantic 扩展欧几里得
romantic扩展欧几里得#include<bits/stdc++.h>using namespace std;typedef long long ll;ll exgcd(ll a,ll b,ll &x,ll &y){ if(b==0) { x=1; y=0; return a; } ...原创 2018-05-09 23:41:57 · 129 阅读 · 0 评论 -
排列:计算1!+2*2!+3*3!+...+n*n!
排列:计算1!+2*2!+3*3!+...+n*n!https://nanti.jisuanke.com/t/30990原式=(2-1)x1!+2x2!+3x3!+4x4!+.....+nxn!=2!-1+2x2!+3x3!+4x4!+.....+nxn!=(1+2)x2!-1+3x3!+4x4!+.....+nxn!=3!-1+3x3!+4x4!+.....+nxn!=(1+3...原创 2018-09-03 21:56:12 · 2192 阅读 · 0 评论