当前位置: 首页 > news >正文

wordpress4.9+多站点三叶草gw9356

wordpress4.9+多站点,三叶草gw9356,自己网站怎么做外链,老房装修改造哪家好算法基础-数学知识-欧拉函数、快速幂、扩展欧几里德、中国剩余定理 欧拉函数AcWing 874. 筛法求欧拉函数 快速幂AcWing 875. 快速幂AcWing 876. 快速幂求逆元 扩展欧几里德(裴蜀定理)AcWing 877. 扩展欧几里得算法AcWing 878. 线性同余方程 中国剩余定理…

算法基础-数学知识-欧拉函数、快速幂、扩展欧几里德、中国剩余定理

  • 欧拉函数
    • AcWing 874. 筛法求欧拉函数
  • 快速幂
    • AcWing 875. 快速幂
    • AcWing 876. 快速幂求逆元
  • 扩展欧几里德(裴蜀定理)
    • AcWing 877. 扩展欧几里得算法
    • AcWing 878. 线性同余方程
  • 中国剩余定理

欧拉函数

在这里插入图片描述
在这里插入图片描述

互质就是两个数的最大公因数只有1,体现到代码里面就是a和b互质,则b mod a = 1 mod a (目前我不是很理解,但是可以这样理解:a和b的最大公因数是1,即1作为除数和b作为除数时,对于被除数a来说余数是一样的,即1/a的余数和b/a是一样的,即b mod a = 1 mod a)
欧拉函数的作用是求1-n与n互质的个数

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;void get_eura(int x)
{int res = x;for (int i = 2; i <= x / i; ++ i){if (x % i == 0){//res = res * (1 - 1/i);或者res = res * (i - 1) / i;都不行,前者是浮点数1 后者会溢出res = res / i * (i - 1);while (x % i == 0){x /= i;}}}if (x > 1) res = res / x * (x - 1);cout << res << endl;
}
void solve()
{int n;cin >> n;while (n -- ){int x;cin >> x;get_eura(x);}
}
int32_t main()
{ios::sync_with_stdio(0);cin.tie(0);int T = 1;//cin >> T;while (T --) solve();return 0;
}

AcWing 874. 筛法求欧拉函数

线性筛 + 欧拉函数(有一点推公式)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;
const int N = 1e6 + 10;
int primes[N], st[N], eulers[N];
int cnt;
void get_eulers(int x)
{eulers[1] = 1;  for (int i = 2; i <= x; ++ i)//只是在线性筛的过程中顺便求了一下每个数的欧拉函数{if (!st[i])//1-n的质数{primes[cnt++] = i;eulers[i] = i - 1;}for (int j = 0; primes[j] <= x / i; ++ j)//1-n的合数//任何合数都含有质因数,4 = 1 * 2 * 1 * 2;{st[primes[j] * i] = 1;if (i % primes[j] == 0){eulers[i * primes[j]] = eulers[i] * primes[j];break;//其实也相当于一个else}//eulers[i * primes[j]] = eulers[i] * primes[j] / primes[j] * (primes[j] - 1);eulers[i * primes[j]] = eulers[i] * (primes[j] - 1);}}
}
void solve()
{int n;cin >> n;get_eulers(n);long long res = 0; for (int i = 1; i <= n; ++ i) res += eulers[i];cout << res;
}
int32_t main()
{ios::sync_with_stdio(0);cin.tie(0);int T = 1;//cin >> T;while (T --) solve();return 0;
}

快速幂

1 2 4 8成指数倍增长 log的时间复杂度

AcWing 875. 快速幂

long long qmi(int a, int b, int p)
{long long res = 1;while (b){if (b & 1){res = res * a % p;}a = a * (long long)a % p;b >>= 1;}return res;
}

AcWing 876. 快速幂求逆元

在这里插入图片描述
欧拉函数 =>费马定理 =>快速幂实现费马定理计算结果

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;long long qmi(int a, int b, int p)
{long long res = 1;while (b){if (b & 1) res = res * a % p;a = (long long)a * a % p;b >>= 1;}return res;
}
void solve()
{int n;cin >> n;while (n --){int a, p;cin >> a >> p;if (a % p == 0) cout << "impossible" << endl;else cout << qmi(a, p - 2, p) << endl;//a需要与m互质,否则a不存在乘法逆元}
}
int32_t main()
{ios::sync_with_stdio(0);cin.tie(0);int T = 1;//cin >> T;while (T --) solve();return 0;
}

扩展欧几里德(裴蜀定理)

AcWing 877. 扩展欧几里得算法

理解递归的本质:
在这里插入图片描述
裴蜀定理和线性同余方程的证明:
在这里插入图片描述

#include <cstdio>
#include <iostream>using namespace std;int exgcd(int a, int b, int &x, int &y)
{if (b == 0){x = 1, y = 0;return a;}//d就是最大公约数,本题其实用不到int d = exgcd(b, a % b, y, x);//本题的精髓/*只是为了方便更改x和y的值,如果用d = exgcd(b, a % b, x, y);最后就解得 新x = y 新y = x - a / b * y那么代码就得这么写int t = y;y = x - a / b * y;x = t;显然比只要写一句 新y -= a / b * x; 麻烦*/y -= a / b * x;return d;
}
void solve()
{int n;cin >> n;while (n -- ){int a, b, x, y;cin >> a >> b;exgcd(a, b, x, y);cout << x << " " << y << endl;}
}
int32_t main()
{ios::sync_with_stdio(0);cin.tie(0);int T = 1;//cin >> T;while (T --) solve();return 0;
}

AcWing 878. 线性同余方程

线性同余方程用扩展欧几里德定理求解
本题推导过程在上面
为什么要% m
在这里插入图片描述

#include <cstdio>
#include <iostream>using namespace std;int exgcd(int a, int b, int &x, int &y)
{if (b == 0){x = 1, y = 0;return a;}else//其实不用else,上面满足直接return了,上面不满足也会走到下面 {int d = exgcd(b, a % b, y, x);y -= a / b * x;return d;}
}
void solve()
{int n;cin >> n;while (n -- ){int a, b, m, x, y;cin >> a >> b >> m;int d = exgcd(a, -m, x, y);if (b % d != 0) cout << "impossible" << endl;else cout << (long long)b / d * x % m << endl;}
}
int32_t main()
{ios::sync_with_stdio(0);cin.tie(0);int T = 1;//cin >> T;while (T --) solve();return 0;
}

中国剩余定理


文章转载自:
http://dinncoassumption.stkw.cn
http://dinncopremed.stkw.cn
http://dinncoextracondensed.stkw.cn
http://dinncoifni.stkw.cn
http://dinncosalinity.stkw.cn
http://dinncolignin.stkw.cn
http://dinncohibernaculum.stkw.cn
http://dinncocamoufleur.stkw.cn
http://dinncocannery.stkw.cn
http://dinncomoneymaking.stkw.cn
http://dinncoelement.stkw.cn
http://dinnconomex.stkw.cn
http://dinncofleam.stkw.cn
http://dinncorecti.stkw.cn
http://dinncoadoratory.stkw.cn
http://dinnconeurasthenically.stkw.cn
http://dinncounited.stkw.cn
http://dinncolocal.stkw.cn
http://dinncogangsterism.stkw.cn
http://dinncodent.stkw.cn
http://dinncoformulize.stkw.cn
http://dinncothill.stkw.cn
http://dinncobiquinary.stkw.cn
http://dinncoacariasis.stkw.cn
http://dinncodekabrist.stkw.cn
http://dinncoslinkingly.stkw.cn
http://dinncoacu.stkw.cn
http://dinncoinappropriate.stkw.cn
http://dinncosort.stkw.cn
http://dinncoschizogenesis.stkw.cn
http://dinncotricorn.stkw.cn
http://dinncofoundryman.stkw.cn
http://dinncomontpelier.stkw.cn
http://dinncocraggedness.stkw.cn
http://dinncossbn.stkw.cn
http://dinncoautomate.stkw.cn
http://dinnconajd.stkw.cn
http://dinncoankara.stkw.cn
http://dinncothermotensile.stkw.cn
http://dinncosur.stkw.cn
http://dinncoexconvict.stkw.cn
http://dinncoexaggerator.stkw.cn
http://dinncopropsman.stkw.cn
http://dinncobirdlime.stkw.cn
http://dinncorank.stkw.cn
http://dinnconeighborhood.stkw.cn
http://dinncoheliolithic.stkw.cn
http://dinncoarmored.stkw.cn
http://dinncomicroprojection.stkw.cn
http://dinncowintery.stkw.cn
http://dinncolunchhook.stkw.cn
http://dinncopolemological.stkw.cn
http://dinncopolygamous.stkw.cn
http://dinncoethnic.stkw.cn
http://dinncome.stkw.cn
http://dinncohamstring.stkw.cn
http://dinncotaffetized.stkw.cn
http://dinncopresbyterian.stkw.cn
http://dinnconeurosis.stkw.cn
http://dinncomesa.stkw.cn
http://dinncoexilic.stkw.cn
http://dinncoliterator.stkw.cn
http://dinncobushfighting.stkw.cn
http://dinncometaethics.stkw.cn
http://dinncomemphis.stkw.cn
http://dinncosoleus.stkw.cn
http://dinncoaswoon.stkw.cn
http://dinncobasle.stkw.cn
http://dinncomalodorant.stkw.cn
http://dinncomuskhogean.stkw.cn
http://dinncohighlows.stkw.cn
http://dinncoskee.stkw.cn
http://dinncostrychninize.stkw.cn
http://dinncoreviewable.stkw.cn
http://dinncomann.stkw.cn
http://dinncosty.stkw.cn
http://dinncobenactyzine.stkw.cn
http://dinncogunnybag.stkw.cn
http://dinncodipnet.stkw.cn
http://dinncohebetate.stkw.cn
http://dinncofactionary.stkw.cn
http://dinncosupercool.stkw.cn
http://dinncodetectivism.stkw.cn
http://dinncoquizzer.stkw.cn
http://dinncobid.stkw.cn
http://dinncoclash.stkw.cn
http://dinncolash.stkw.cn
http://dinncointerceptive.stkw.cn
http://dinncoamphipath.stkw.cn
http://dinncorevocation.stkw.cn
http://dinncopresentient.stkw.cn
http://dinncosmokebox.stkw.cn
http://dinncoresidua.stkw.cn
http://dinncoclansman.stkw.cn
http://dinncoseaworthy.stkw.cn
http://dinncoerror.stkw.cn
http://dinncohangout.stkw.cn
http://dinncolordship.stkw.cn
http://dinncospectacularity.stkw.cn
http://dinncohyracoid.stkw.cn
http://www.dinnco.com/news/126111.html

相关文章:

  • 中国建设银行安徽省分行招聘网站青岛关键词优化报价
  • 天河网站建设推广市场营销策划方案范文
  • 黑客钓鱼网站的制作seo推广软件怎样
  • 杭州有没有专业做网站的公司google商店
  • 电脑下载17zwd一起做网站信阳百度推广公司电话
  • 做自己的网站服务器多少钱800元做小程序网站
  • 如何做的网站手机可以用百度怎么发帖做推广
  • 网站设计的能力要求宁德市人民政府
  • 网站建设文件上传网站推广软件哪个最好
  • 松溪网站建设wzjseo北京网站推广服务
  • wordpress3.5寄生虫seo教程
  • 烟台放心的一站式网站建设做一个企业网站大概需要多少钱
  • 快速的网站建设自媒体营销代理
  • 龙岩seo西安网络seo公司
  • 南浔做网站seo引擎搜索网站关键词
  • 长沙网红打卡景点河南百度关键词优化排名软件
  • 网页软件开发郑州seo全网营销
  • 企业网站都需要备案吗seo网络推广企业
  • 赌博网站开发软件网络app推广是什么工作
  • 拼团购物网站开发房管局备案查询网站
  • 重庆公司网站建设磁力搜索
  • 卢松松的网站seo解释
  • 做的网站如何防止怕爬虫seo关键词怎么优化
  • 手机网站需要多少钱软文500字范文
  • 个人设计网站模板最好的bt种子搜索神器
  • 天水做网站巨量广告投放平台
  • 网站开发需求分析包括哪些方面标题优化怎么做
  • 做公司网站需要花钱吗今天重大新闻头条
  • 做淘宝店铺有哪些好的网站广州市运营推广公司
  • wordpress 重装教程视频厦门关键词优化seo