
水题
KingsCC
这个作者很懒,什么都没留下…
展开
-
求最大公约数
定理 当a,b不为0时,a和b的最大公约数与b和amodb的最大公约数相同;当a和b其中一个为0时,另一个非零值则为最大公约数#include<iostream>#include<string.h>using namespace std;int main(){ int a, b; while (cin >> a >> b...原创 2018-08-18 17:00:52 · 225 阅读 · 0 评论 -
最小公倍数
与两数乘积/最大公约数等价#include<iostream>#include<string.h>using namespace std;int gcd(int a, int b){ if (b == 0)return a; else return gcd(b, a%b);}int main(){ int a, b; whi...原创 2018-08-18 17:11:14 · 543 阅读 · 0 评论 -
求素数
#include<iostream>#include<string.h>#include<math.h>using namespace std;int main(){ int n,flag; while (cin >> n) { flag = 0; if (n <= 1) ...原创 2018-08-18 17:22:44 · 213 阅读 · 0 评论 -
素数筛法
#include<iostream>#include<string.h>#include<math.h>using namespace std;int a[10001];//0未知 1素数 2非素数int main(){ memset(a, 0, sizeof(a));//预处理 for (int i = 2; i <...原创 2018-08-18 17:58:28 · 195 阅读 · 0 评论 -
素因数分解
#include<iostream>#include<string.h>#include<math.h>using namespace std;int a[100001];//0未知 1素数 2非素数int main(){ memset(a, 0, sizeof(a)); for (int i = 2; i < 10000...原创 2018-08-18 19:02:29 · 945 阅读 · 0 评论 -
特殊乘法 %
题目:求两个小于十亿的数,按位相乘再相加如12*45=1*4+1*5+2*4+2*5法1:#include<iostream>#include<string.h>using namespace std;char a[10], b[10];int main(){ while (cin >> a >> b) { ...原创 2018-08-17 17:16:06 · 347 阅读 · 0 评论 -
10进制转m进制
1<m<10#include<iostream>#include<string.h>using namespace std;int a[1000],i;//10进制转m进制void _10tom(int m,long long num){ //确保数为0时至少执行一次do { a[i++] = num%m; ...原创 2018-08-17 17:43:43 · 371 阅读 · 0 评论