俯视膜拜初等数论
来源:互联网 发布:启云软件怎么样 编辑:程序博客网 时间:2024/04/28 11:09
第一部分:质数
质数
又称素数,有无限个。质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数。
质数是一个孤独的数字呀!
质因数分解
什么是质因数分解?
就是将一个数字分解成几个质数相乘。小学时候我们就学过的,很简单。比如
有什么用?
用处很大很大的!后面的求欧拉函数就是在这个的基础之上建立的。
思路是什么?
我暂时也不能理解为什么这么干。
代码
#include<iostream>#include<vector>#include<cmath>using namespace std;vector<int> factor(int n){ vector<int> ans; for (int i = 2; i <= sqrt(n); i++) { while (n%i == 0) { ans.push_back(i); n /= i; } } if (n > 1) { ans.push_back(n); } return ans;}int main(){ int n; cin >> n; vector<int>ans=factor(n); for (int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; }}
欧拉函数
欧拉函数是什么?
在数论,对正整数
这里有一个求欧拉函数的简便方法
思路
基于上面的分解质因数的算法
代码
XX
第二部分:求解不定方程
欧几里得算法
扩展欧几里得算法
怎么证明是对的?
忘了
有什么用?
可以用来求
那么问题来了如何求
举个例子:
我可以直接先求
代码
#include <iostream>using namespace std;int gcdEx(int a, int b, int &x, int &y) { if(b==0) { x=1; y=0; return a; } int r = gcdEx(b, a%b, x, y); int x1 = x, y1 = y; x = y1; y = x1 - (a / b) * y1; return r;}int main(){ int x, y; cout<<gcdEx(47, 30, x, y)<<"\n"; cout<<x<<" "<<y; return 0;}
解二元一次不定方程
有什么卵用?
可以求逆元啊!!
同余方程可以转为不定方程,所以解同余方程可以看成解不定方程。
代码
#include <iostream>using namespace std;int gcdEx(int a, int b, int &x, int &y){ if (b == 0) { x = 1; y = 0; return a; } int r = gcdEx(b, a%b, x, y); int x1 = x, y1 = y; x = y1; y = x1 - (a / b) * y1; return r;}int main(){ int x, y; int a, b, c; //ax+by=c cin >> a >> b>> c; int numGcd = gcdEx(a, b, x, y); cout << c / numGcd * x << " " << c / numGcd * y; return 0;}
逆元
逆元是什么?逆天啊!
当a,m互质,若
逆元有什么用?
我也不知道
怎么求逆元
当a,m互质,
注意解出的x可能是负数,如果是负数我们就直接加上m就行了。依据是不定方程通解公式,如下。
思路
就把它当做一个不定方程的问题来处理就行了。
代码
#include<iostream>#include<vector>#include<cmath>using namespace std;int exgcd(int a, int b, int &x, int &y){ if (b == 0) { x = 1; y = 0; return a; } int r = exgcd(b, a%b, x, y); int x1 = x; int y1 = y; x = y1; y = x1 - (a / b) * y1; return r;}// 求逆元int inverse(int a, int m){ int x, y; exgcd(a, m, x, y); return x;}int main(){ int a, m; cin >> a >> m; int ans = inverse(a, m); if (ans < 0) { cout << ans + m; } else { cout << ans; }}
- 俯视膜拜初等数论
- 初等数论
- 初等数论
- 初等数论
- 初等数论重要定理
- 初等数论笔记
- 初等数论零散总结
- 初等数论1
- ACM初等数论
- 初等数论学习
- 初等数论2
- 初等数论总结
- POJ1365 Prime Land 初等数论
- (初等数论)我是好人
- 初等数论总结(填坑)
- 初等数论-扩展欧几里德算法
- 初等数论_1 2016.3.30
- 初等数论_2 2016.4.1
- solr-4.10.3的IK Analyzer分词器配置
- Linux 在终端中打开新的终端:gnome-terminal
- android Studio运行时,出现java.lang.NoClassDefFoundError
- PAT 1016. 部分A+B (15)
- LinuxC语言概述及开发工具的使用
- 俯视膜拜初等数论
- 1.4 对齐输出
- Starship Troopers (树形dp+背包)
- Python线程合并和后台线程
- ELK之索引应用
- 用C++语言实现贪吃蛇游戏
- 请问Java中抽象类中的抽象方法是否一定要被继承类实现?
- python--leetcode653. Two Sum IV
- C : 你说什么?我不会a+b?