
数论
幽殇默
他时若遂凌云志,敢笑黄巢不丈夫。
展开
-
B. Omkar and Last Class of Math【1300 / 数论】
https://codeforces.com/problemset/problem/1372/B其实可以才出来就是求约数。例如: 8=2*4 那么可以分成 4 4例如: 16=4*4 那么可以分成 4 12 必可以是它的约数随着约数的增大,我们的分的第二份越来越小,越来越是正解。#include<bits/stdc++.h>using namespace std;int main(void){ int t; cin>>t; while(t.原创 2021-11-06 23:14:44 · 137 阅读 · 0 评论 -
C. Product of Three Numbers【1300 / 简单数论】
https://codeforces.com/problemset/problem/1294/C#include<bits/stdc++.h>using namespace std;int main(void) { int t; cin>>t; while(t--) { int n; cin>>n; bool flag=0; for(int i=2;i<=n/i;i++) { if(n%i==0) { int te.原创 2021-11-05 22:22:35 · 135 阅读 · 0 评论 -
D. Buying Shovels【1300 / 求约数】
https://codeforces.com/problemset/problem/1360/D就是看可不可以整除,这不就是约数么,注意要不大于k#include<bits/stdc++.h>using namespace std;int main(void){ int t; cin>>t; while(t--) { int n,k; cin>>n>>k; int ans=n; for(int i=1;i<=n/i;i++).原创 2021-11-04 23:40:05 · 113 阅读 · 0 评论 -
C. Fadi and LCM【1400 / 数论】
https://codeforces.com/problemset/problem/1285/C题目要求的是max(a,b)尽可能的小,故考虑对n分解约数。让俩约数尽可能的接近。且满足gcd(a,b)==1#include<bits/stdc++.h>using namespace std;typedef long long int LL;LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}LL x,y;int main(void){ LL n.原创 2021-11-01 23:04:07 · 118 阅读 · 0 评论 -
B. Random Teams【1300 / 组合数学】
https://codeforces.com/problemset/problem/478/B#include<bits/stdc++.h>using namespace std;typedef long long int LL;LL n,m;LL get1(LL n,LL m)//最小 尽量的均分 { LL b=n/m; if(n%m)//不可以平均分 { int temp=n-b*m; LL sum=0; for(int i=1;i<=m;i++) .原创 2021-10-26 12:56:34 · 171 阅读 · 0 评论 -
B. T-primes【1300 / 思维 数论】
https://codeforces.com/problemset/problem/230/B首先分析一下: 只有三个因子 例如 4 除去1和4 还有一个。我们都知道因子几乎都是一对的出现的,只有平方数是有单个的因子。故必是一个平方数,且1-sqrt(x) 之间不准有多余的因子。说明了 sqrt(x)是一个质数。故可以得出结论质数的平方数只有三个因子#include<bits/stdc++.h>using namespace std;typedef long long LL;.原创 2021-10-24 20:21:40 · 321 阅读 · 0 评论 -
198. 反素数【数论】
https://www.acwing.com/problem/content/description/200/2*3*5*7*11*13*17*19*23*>2*109且质数的次数是依次递减的#include<bits/stdc++.h>using namespace std;typedef long long int LL;LL p[10]={2,3,5,7,11,13,17,19,23};LL maxv,ans,n;void dfs(LL index,LL last,.原创 2021-10-16 15:29:20 · 97 阅读 · 0 评论 -
1294. 樱花【推式子 / 约数个数】
https://www.acwing.com/problem/content/1296/#include<bits/stdc++.h>using namespace std;const int N=1e6+10;const int mod=1e9+7;typedef long long int LL;LL prime[N],st[N],cnt,n;void init(){ for(int i=2;i<=1e6;i++) { if(!st[..原创 2021-10-15 13:31:51 · 170 阅读 · 0 评论 -
1291. 轻拍牛头【约数】
https://www.acwing.com/problem/content/description/1293/暴力做法:O(n2)#include<bits/stdc++.h>using namespace std;const int N=1e5+10;int a[N],cnt[N],n;int main(void){ cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i.原创 2021-10-15 12:44:29 · 101 阅读 · 0 评论 -
196. 质数距离【筛指定一个大区间内的质数】
https://www.acwing.com/problem/content/description/198/数据范围很大,但是区间不大。一个合数必定有一个质数因子。因此只要筛其质因子,再枚举每一个质因子判断即可。#include<bits/stdc++.h>using namespace std;typedef long long int LL;const int N=1e6+10;int prime[N],st[N],cnt;LL l,r;int init(int n).原创 2021-10-15 11:13:43 · 158 阅读 · 0 评论 -
197. 阶乘分解【数论】
https://www.acwing.com/problem/content/description/199/可以轻松的想到的是: 枚举阶乘的每一个数,对每一个数进行分解质因子。但是会TLE。我们不防先处理出一个素数表。然后枚举每一个素数求其该素数对应的次数。#include<bits/stdc++.h>using namespace std;const int N=1e6+10;int prime[N],st[N],cnt,n;void init(int n){ for(i.原创 2021-10-10 10:33:57 · 152 阅读 · 0 评论 -
1292. 哥德巴赫猜想【数论 线性筛】
https://www.acwing.com/problem/content/description/1294/#include<bits/stdc++.h>using namespace std;const int N=1e6+10;int st[N],prime[N],cnt,t;void init(){ int n=1e6; for(int i=2;i<=n;i++) { if(!st[i]) prime[cnt++]=i; .原创 2021-10-08 21:50:09 · 129 阅读 · 0 评论 -
B. Different Divisors【1000 / 数论 思维】
https://codeforces.com/problemset/problem/1474/B首先1一定是一个因子,我们找到第一个距离1大于等于d的质数a。在找到第二个距离第一个a距离大于等于d的质数b。答案就是 a*b 因子有1 a b a*b 共四个感觉这个结论只能打表找规律,或者看样例的答案推出来。#include<bits/stdc++.h>using namespace std;const int N=1e6+10;int st[N],prime[N],cnt,d.原创 2021-10-03 16:01:03 · 120 阅读 · 0 评论 -
A. CQXYM Count Permutations【800 / 数学】
https://codeforces.com/contest/1581/problem/A最简单的方法就是看样例其实可以才出来结果就是(n*2)!/2 因为要对除法取余,故需要求逆元。正解: 根据对称性可以得出,合法的答案和不合法的答案是平分所有的方案的。#include<bits/stdc++.h>using namespace std;const int N=1e5*2+10;const int mod=1e9+7;typedef long long int LL;LL .原创 2021-10-01 10:54:51 · 225 阅读 · 0 评论 -
A. Game 23 【1000 / 分解因子】
https://codeforces.com/problemset/problem/1141/A#include<bits/stdc++.h>using namespace std;typedef long long int LL;int main(void){ LL a,b; cin>>a>>b; if(b%a!=0) puts("-1"); else { LL n=b/a; LL ans=0; while(n%3==0) ans++,.原创 2021-09-29 08:43:06 · 114 阅读 · 0 评论 -
B. Mahmoud and a Triangle【1000 / 数学 】
https://codeforces.com/problemset/problem/766/B就是问有没有三条边可以构成三角形。#include<bits/stdc++.h>using namespace std;const int N=1e5+10;int a[N],n;bool check(int a,int b,int c){ if(a+b<=c) return false; if(a+c<=b) return false; if(b+c<=a) r.原创 2021-09-24 22:12:15 · 111 阅读 · 0 评论 -
3725. 卖罐头
摘自: https://www.acwing.com/solution/content/54259/#include<bits/stdc++.h>using namespace std;int main(void){ int t; cin>>t; while(t--) { int l,r; cin>>l>>r; if(r<l*2) puts("YES"); else p..原创 2021-08-20 17:24:20 · 122 阅读 · 0 评论 -
直角三角型 【数学】
https://www.nowcoder.com/practice/54ef7fa64c63442d87b9c836ef9c7701?tpId=40&tqId=31012&rp=1&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan%2Fquestion-ranking&tab=answerKey#include<cmath>#include<cstring>#include<iostream>usi.原创 2021-04-06 21:48:41 · 82 阅读 · 0 评论 -
【1249】 三角形 【简单递推 / 数论】
http://acm.hdu.edu.cn/showproblem.php?pid=1249我们要知道的是要想分成的区域越多,那么交点必须越多当我们的三角形有2个的时候。固定一个三角形,画另一个三角形,要想让其分成的区域越多,故边穿过的线的个数必须多。一条线最多穿过 2条线,三角形有三条边故 一共有 3*2= 6个交点s[2] =s[1] +6 =8;不难得到 s[3]=s[2]+3*2(3-1)...原创 2021-05-08 19:29:16 · 166 阅读 · 0 评论 -
【1220】 Cube【简单数论】
http://acm.hdu.edu.cn/showproblem.php?pid=1220用全部的方案数 - 挨着的方案数 就是结果。#include<cstdio>#include<iostream>using namespace std;int main(void){ int a; while(cin>>a) { cout<<(a*a*a)*(a*a*a-1)/2-(a-1)*a*2*a-a*a*(a-1)<<en.原创 2021-05-08 19:08:10 · 101 阅读 · 0 评论 -
【1214】 圆桌会议 有意思的数论
http://acm.hdu.edu.cn/showproblem.php?pid=1214不得不佩服杭电里的题确实新颖。题意: 是这样的让这个圆翻转一下,问其最小的步数圆圈不好想,那么我们先用一条线来想。这不就是一个冒泡排序,问排序数字移动的次数么?那么圆圈该如何移动? 其实是一样的不过我们要分两段,分别的移动。原因是这样的:我们粗略的看成 n x n 假如 n=5 则sum=5x5=25如果我们分成两段 sum=2x2+3x3=13 步数明显的要少。至于.原创 2021-05-08 13:57:02 · 479 阅读 · 0 评论 -
【1021】Fibonacci Again 【简单数论】
http://acm.hdu.edu.cn/showproblem.php?pid=1021目测朴素算法肯定是不行的,一定会爆 long long .经过打表发现打了前100就爆了。那么只有找规律了,题目问的是能不能整除3 只要对每一个数模上一个3 就可以了。#include<cstdio>#include<iostream>using namespace std;const int N=1e6+10;int a[N];int main(void){ int.原创 2021-05-06 20:49:57 · 127 阅读 · 0 评论 -
【1018】 Big Number 【简单数论】
高精度计算肯定会超时,高精代码如下:我还做了去除后导零进行优化但是仍会超时。#include<cstdio>#include<iostream>#include<vector>using namespace std;int cnt=0;vector<int> mtl(vector<int> A,int d){ vector<int> C; int t=0; for(int i=0;i<A.size()||t.原创 2021-05-06 20:20:50 · 146 阅读 · 0 评论 -
【2104】 hide handkerchief 【数论 / 有意思】
题目的意思: n个人围成一个圈,以步长为m 来一直找,看所有的数会不会全部找到。模拟做法:#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(void){ int n,m; while(cin>>n>>m,n!=-1||m!=-1) { int i=0; bool a[n]; while(!a[i])//不重.原创 2021-05-06 11:02:50 · 142 阅读 · 0 评论 -
猴子排序的期望 【高精乘和除 / 组合数学】
https://ac.nowcoder.com/acm/problem/15825扔N张卡片,次序有N!种可能。故 sum=N!但是其中可能有重复的组合,设字符A的重复次数为x,则有x!种同一排序,其他字符同理计算。根据乘法原理,总的重复次数有x1!* x2!* x3!*…xk!。故去重后的 sum= N! / (x1!* x2!* x3!*…xk! )#include<cstdio>#include<iostream>#include<vector>.原创 2021-05-17 22:58:06 · 268 阅读 · 0 评论 -
P1226 【模板】快速幂||取余运算
https://www.luogu.com.cn/problem/P1226#include<cstdio>#include<iostream>using namespace std;#define LL long long int LL a,b,m;int f(LL a,LL b,LL m){ LL sum=1; a=a%m; while(b) { if(b&1) sum=(sum*a)%m; a=(a*a)%m; b=b>>.原创 2021-05-13 22:55:22 · 94 阅读 · 0 评论 -
P3383 【模板】线性筛素数
https://www.luogu.com.cn/problem/P3383#include<cstdio>#include<iostream>using namespace std;const int N=1e7+10;const int M=1e8+10;int primes[N],cnt;bool st[M];void print(int n){ for(int i=2;i<=n;i++) { if(!st[i]) primes[cnt++]=.原创 2021-05-13 22:27:52 · 149 阅读 · 0 评论 -
求n!的位数【数论】
首先,我们要知道如何请求一个数的位数是多少。例: 123 它的位数=log10(123)+1 最后再取整原创 2021-05-06 20:17:56 · 115 阅读 · 0 评论 -
求2的零次方 加 2的一次方 加2的二次方等等的和
问题描述:a0+a1+a2+…+ac等于多少。#include<cstdio>#include<iostream>using namespace std;int f(int a,int c){ int sum=1; for(int i=1;i<=c;i++) { sum=sum*a+1; } return sum; }int main(void){ int a,c; cin>>a>>c; cout<<f原创 2021-05-05 11:35:22 · 1485 阅读 · 0 评论 -
平面上有N条直线,最多有几个交点
sum=n(n-1)/2 (n是直线的个数)视频讲解原创 2021-05-03 09:55:43 · 1007 阅读 · 0 评论 -
T166291 「RdOI R2」数(number) 试求出三个正整数使得其中的任意两个数的和能被第三个数整除。
https://www.luogu.com.cn/problem/T166291?contestId=43149找规律会发现,满足的数的比值是 3:2:1#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<string>using namespace std;int a,b,c;int main(void){ int n; ci.原创 2021-05-02 19:17:53 · 199 阅读 · 0 评论 -
斐波那契数列公式法
https://www.luogu.com.cn/problem/P1720#include<cmath>#include<iostream>#include<cstdio>using namespace std;int main(void){ double a=(1+sqrt(5))/2; double b=(1-sqrt(5))/2; int n; cin>>n; double a1=1; double a2=1; for(int.原创 2021-04-30 11:07:46 · 529 阅读 · 0 评论 -
凸多边形对角线交点的个数
https://www.luogu.com.cn/problem/P2181首先一个交点对应两条对角线,二这两条对角线是有四个点确定的。所以只要求C4nnn就可以了 即 n(n-1)(n-2)(n-3)/24#include <cstdio>#include <cstring>#include <cmath>unsigned long long n; int main(){ //读入 scanf("%lld",&n); //计.原创 2021-04-30 09:44:40 · 902 阅读 · 0 评论 -
盛金公式解一元三次方程
转载自: https://www.luogu.com.cn/problem/solution/P1024?page=4#include<bits/stdc++.h> using namespace std; double a,b,c,d,A,B,T,ac,x1,x2,x3; int main(){ ios::sync_with_stdio(false); cin.tie(0); ..转载 2021-04-28 19:10:04 · 553 阅读 · 0 评论