数学基础
1
infinity°º
stay hungry stay foolish
展开
-
大数加减比较
str.erase(0,str.find_first_not_of('0'));//去除结果中多余的前导0 carry为借位和进位 string add(string str1,string str2) { string str; int len1=str1.length(); int len2=str2.length(); if(len1>len2) for(int i=1;i<=len1-len2;i++) st.原创 2021-11-19 22:00:32 · 171 阅读 · 0 评论 -
建塔 (高级二分,再多思考一下)
#include<bits/stdc++.h> typedef long long ll; using namespace std; const int maxn=1e5+7; int n,k; ll a[maxn],b[maxn],c[maxn]; //判断能否建k座塔 bool check(int x){ int i,j; //建底层 for(int i=1;i<=x;i++) b[i]=a[i],c[i]=1;//b记录每座塔顶层的数据,c记录塔高 //一层.原创 2021-08-23 20:53:34 · 49 阅读 · 0 评论 -
序列划分(高级二分)
方法:针对问题构造递增..函数,再套用二分 使用题型: ( 对..的最大(最小)取最小(最大)) f(x)函数递减or增(可有相等项),可把f看成数组,用二分 而x表示的是每段数字之和,f值为至少划分的段数。所以 l:最少一个数(但必须是最大那个)占一段,r:对多所有数一段 题目要求划分成m段,所以f(mid)的值与m比较,后修改lr #include<bits/stdc++.h> typedef long long ll; using namespace std; const int .原创 2021-08-23 20:17:21 · 735 阅读 · 1 评论 -
hdu3494线性基模板
//分析: //求第k大:把k二进制拆分,如果k的第i位上是1,ans^=b[i] //d[i]表明第i位(权为2^i)是否为1,并存入使第i位为1的线性基是几 #include<bits/stdc++.h> typedef long long ll; using namespace std; const int maxn=63; ll d[maxn+1]; int main(){ int t,id=0,r,n,m,k; ll x; cin>>t; while(t--.原创 2021-08-23 14:20:41 · 81 阅读 · 0 评论 -
phi。。。。
越到后面,互质出现的频率越小,所以phi[1000003]=1000000即n未1000000时也只需要1000003,所以ll也不用 #include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn=1e6+7; int p[maxn],phi[maxn]; void f(){ int cnt=0; memset(phi,0,s.原创 2021-08-22 17:01:31 · 101 阅读 · 0 评论 -
hdu2588题意 转 欧拉函数(模板)
#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; //求n的欧拉函数值 ll oula(int n){ ll ans=n;//n=1是 ans为1 //因为只和因子有关,所以只需看根号n内的就行 for(int i=2;i*i<=n;i++){ if(n%i==0){//找到n的因子 ans=ans-ans/i;//欧拉函数的公式(实质是.原创 2021-08-21 19:01:56 · 80 阅读 · 0 评论 -
hdu2824线性求(即求n内所有)欧拉函数值phi模板
1与任何数互质 4和15互质,4 15都不是质数,但互质 即gcd(4,15)=1 #include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn=3e6+7; int vis[maxn],p[220000],phi[maxn],cnt=0; //欧拉线性筛通过唯一分解法删合数(min质数*剩余部分)12=2*6,通过质数2来删 //线性筛.原创 2021-08-21 16:52:32 · 177 阅读 · 0 评论 -
hdu3579crt求最小正数解,无解输出-1
#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; int m[7],a[7],n,flag; int exgcd(int a,int b,int &x,int &y){ if(!b){ x=1;y=0;return a; } int d=exgcd(b,a%b,x,y); int t=x; x=y;y=t-a/b.原创 2021-08-21 09:59:42 · 102 阅读 · 0 评论 -
hdu1286欧拉函数
#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn=33*1e3; int a[maxn]; int main(){ int t,n; cin>>t;//这里输出有点怪 t, 没事不用管 while(t--){ cin>>n; //除会长外是1~n-1,而1肯定是n的公约数,直接从2开始 me.原创 2021-08-21 09:46:40 · 89 阅读 · 0 评论 -
hdu1370中国剩余定理crt通用模板(运用到exgcd)
#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn=1e5+5; const int mod=21252; int m[4]={0,23,28,33},a[4],n=3; int exgcd(int a,int b,int &x,int &y){ if(!b){ x=1;y=0;return a; } int d=ex.原创 2021-08-20 23:04:22 · 110 阅读 · 0 评论 -
hdu2669 exgcd裸题
#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; //const int maxn=1e5+5; //const int p=1e9+7; int exgcd(int a,int b,int &x,int &y){ if(!b){ x=1;y=0;return a; } int d=exgcd(b,a%b,x,y); int t=x; x=y.原创 2021-08-20 19:03:10 · 91 阅读 · 0 评论 -
线性求逆元
#include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn=1e5+5; const int p=1e9+7; ll inv[maxn]; ll ksm(ll a,ll b){ ll ans=1; while(b){ if(b%2) ans=(ans*a)%p; b/=2; a=(a*a)%p; } return ans; }.原创 2021-08-19 17:30:43 · 173 阅读 · 0 评论 -
两数相除 取余,要用到逆元。9973,1e9+7等是质数,可用费马小定理
求逆元: 欧几里得(通用) 费马小定理(P为质数,比赛最常见)! 线性求逆元(求P以内的 所有 整数对应的逆元) 欧拉定理(p不是质数) ∏求乘积Σ求和 2016"百度之星" - 资格赛(Astar Round1) promble A 要先预处理使得sum[i]表示从第一个点到第i个点的乘积之和! 然后sum[y]/ sum[x-1] 就是答案! #include<bits/stdc++.h> #define inf 0x3f3f3f3f typedef long long ll.原创 2021-08-19 16:05:50 · 256 阅读 · 0 评论 -
ksm和大数相乘
ll qmul(ll x, ll y, ll mod) // b转化成二进制 从最后一位往前看 (快速加) { ll ret = 0; while(y) { if(y %2) ret = (ret + x) % mod; x = x * 2 % mod;//b准备往前看一位,位权变大, 所以x要*2 y >>= 1; } return ret; } ll qpow(ll a, .原创 2021-08-18 22:40:36 · 84 阅读 · 0 评论 -
hdu1098数学归纳法
#include<bits/stdc++.h> using namespace std; //数学归纳法得 只要保证(18+k*a*x)%65==0即可保证f(x)%65==0 int k; int f(int k){ int a; for(a=0;a<=65;a++){ //从0开始保证非负 if((18+(a%65)*(k%65)%65)%65==0) return a; } return a; } int main(){ while(~scanf("%d".原创 2021-04-01 19:29:32 · 112 阅读 · 0 评论 -
hdu1060(科学计数法,floor)
#include<bits/stdc++.h> using namespace std; int main(){ int t,n; double x; cin>>t; while(t--){ scanf("%d",&n); x=n*log10(n); x=x-floor(x); printf("%d\n",(int)pow(10,x)); } }原创 2021-03-26 15:16:36 · 132 阅读 · 0 评论 -
hdu2899求导二分
#include<bits/stdc++.h> using namespace std; double dao(double x){ return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x; } double f(double x,double y){ return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; } int main(){ int t; cin>>t; do.原创 2021-03-22 18:55:40 · 139 阅读 · 1 评论 -
hdu2899三分法(二次函数可用)
#include<stdio.h> #include<math.h> double f(double x,double y){ return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; } double sf(double y){ double l=0,r=100; double m1,m2; while(r-l>1e-6){ m1=(l*2+r)/3; m2.原创 2021-03-22 18:41:26 · 157 阅读 · 1 评论 -
hdu2199二分求导
#include<bits/stdc++.h> using namespace std; typedef long long ll; double f(double x) { return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6; } int main(){ int t; double y,l,r,m; cin>>t; while(t--){ cin>>y; if(y<6||y>f(100)){ .原创 2021-03-22 18:39:31 · 59 阅读 · 0 评论 -
hdu2035快速幂
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll po(ll a,ll b,ll c){ ll ans=1; ll base=a%c; while(b){ if(b&1) ans=(ans*base)%c; base=(base*base)%c; b>>=1; } return ans; } int main(){ ll a,b; while(scanf(.原创 2021-03-22 18:38:29 · 60 阅读 · 0 评论 -
1097
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll po(ll a,ll b,ll c){ ll ans=1; ll base=a%c; while(b){ if(b&1) ans=(ans*base)%c; base=(base*base)%c; b>>=1; } return ans; } int main(){ ll a,b; while(scanf("%.原创 2021-03-21 19:12:47 · 134 阅读 · 0 评论 -
1021相加取模=分别取模 再相加 再取模
#include<bits/stdc++.h> using namespace std; int f[1000005]; void init(){ f[0]=7;f[1]=11; int i=2; while(i<=1000005){ f[i]=f[i-1]+f[i-2]; f[i]%=3; i++; } } int main(){ int n; init(); while(cin>>n){ if(f[n]%3) cout<<"no".原创 2021-03-21 18:56:59 · 523 阅读 · 0 评论 -
1019
#include<bits/stdc++.h> using namespace std; int gcd(int n,int m){ return m?gcd(m,n%m):n; } int main(){ long long a; int t,n,b; cin>>t; while(t–){ cin>>n; cin>>a; n–; while(n–){ cin>>b; a=a/gcd(a,b)*b; } cout<<a<<e原创 2021-03-21 14:59:49 · 70 阅读 · 0 评论 -
1108
#include<bits/stdc++.h> using namespace std; int gcd(int n,int m){ return m?gcd(m,n%m):n; } int main(){ int n,m; while(cin>>n>>m){ cout<<n*m/gcd(n,m)<<endl; } return 0; }原创 2021-03-21 14:47:32 · 71 阅读 · 0 评论 -
1001
#include<bits/stdc++.h> using namespace std; int main(){ int n,s; while(cin>>n){ s=0; while(n--) s+=n+1; cout<<s<<"\n"<<endl; } return 0; }原创 2021-03-21 14:38:57 · 65 阅读 · 0 评论