数论基础
文章平均质量分 82
Zy_Ming
入门中的ACMer
展开
-
【51nod】1011 最大公约数GCD - 辗转相除法
1011 最大公约数GCD题解:根据辗转相除法直接求得。#include <cstdio>using namespace std;int gcd(int a, int b){ return a == 0 ? b : gcd(b%a, a);}int main(){ int a, b; while(~scanf("%d %d", &...原创 2018-08-24 01:10:18 · 169 阅读 · 0 评论 -
【LightOJ】1179 Josephus Problem - 约瑟夫环
G - Josephus Problem LightOJ - 1179 The historian Flavius Josephus relates how, in the Romano-Jewish conflict of 67 A.D., the Romans took the town of Jotapata which he was commanding. Escaping, Jo...原创 2018-12-06 09:23:47 · 382 阅读 · 0 评论 -
【LightOJ】1297 Largest Box - 一元三次方程
K - Largest Box LightOJ - 1297In the following figure you can see a rectangular card. The width of the card is W and length of the card is L and thickness is zero. Four (x*x) squares are cut from ...原创 2018-12-06 08:58:22 · 186 阅读 · 0 评论 -
【hdu】5974 A Simple Math Problem
A Simple Math Problem题目大意:给出 A 和 B 。A = x + y;B = lcm( x, y)。求 x 和 y 。题解:直观思路,只要求出 x*y 我们就可以直接解方程了。易知 x*y = lcm * gcd。但是 x 和 y 我们都不知道,怎么求 gcd 呢?我们设 gcd( x, y ) = n ,x = a*n ,y = b*n...原创 2018-10-30 14:43:00 · 239 阅读 · 0 评论 -
【hdu】6441 Find Integer - 费马大定理
Find Integer 题解:根据费马大定理很容易知道当 n>2 时,等式 a^n+b^n=c^n 是无整数解的。再假设当 n=0 时,a^0=1。题目中说到 (1≤b,c≤1000,000,000) ,所以此时等式也是无解的。所以,我们只需要再分 n=1 和 n=2 两种情况讨论即可。当 n=1 时,这里就不说了。当 n=2 时,又分为奇偶两种情况。①奇数...原创 2018-08-26 17:14:53 · 181 阅读 · 0 评论 -
【51nod】1014 X^2 Mod P
1014 X^2 Mod P 题解:根据数据来看,直接暴力枚举不会超时。循环里的 i 一定要用 long long!一定要用 long long!一定要用 long long!重要的事情说三遍,做题的时候忘记 i*i 会爆 int ,结果WA了几发!#include <cstdio>using namespace std;int main(){ ...原创 2018-08-26 13:59:25 · 140 阅读 · 0 评论 -
【51nod】1046 A^B Mod C - 快速幂
1046 A^B Mod C 快速幂算法学习#include <cstdio>using namespace std;long long PowerMod(long long a, long long b, long long c){ long long ans = 1; a %= c; while(b){ if(b&a...原创 2018-08-26 13:41:00 · 153 阅读 · 0 评论 -
【51nod】1004 n^n的末位数字
1004 n^n的末位数字 题解:由于题目是问末尾数字,所以我们可以直接对n模10,用最后一位数字进行运算。我们可以列一个表格观察末尾数字自身乘积变化。0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 4 8...原创 2018-08-25 18:20:57 · 189 阅读 · 0 评论 -
【51nod】1181 质数中的质数 - 质数筛法
1181 质数中的质数(质数筛法) 题解:易知,题目要我们求质数。把求得的质数存放于数组 prime[MAXN] 中,同时用 tag[MAXN] 记录质数与非质数。tag[i] == 0 为质数,tag[i] == 1 为非质数。接着循环判断 prime[i] >= n && tag[i] == 0 即可。为了提高效率,这里采用了线性筛法。...原创 2018-08-24 16:03:15 · 393 阅读 · 0 评论 -
【51nod】1008 N的阶乘 mod P - 同余定理
1008 N的阶乘 mod P 题解:这里用到了同余定理(a+b)%m = (a%m + b%m) % m(a*b)%m = (a%m * b%m) % m #include <cstdio>using namespace std;long long Solve(int n, int m){ if(n == 1) return 1...原创 2018-08-24 15:14:28 · 318 阅读 · 0 评论 -
【51nod】1012 最小公倍数LCM - 欧几里德算法
1012 最小公倍数LCM 题解:根据欧几里得算法直接求得。#include <cstdio>using namespace std;long long gcd(long long a, long long b){ return a == 0 ? b : gcd(b%a, a);}int main(){ long long a, b; ...原创 2018-08-24 01:18:17 · 211 阅读 · 0 评论 -
【hdu】2211 杀人游戏
杀人游戏结论推导学习:https://blog.csdn.net/u012717411/article/details/43925433代码:#include <bits/stdc++.h>using namespace std;int t, n, k;int Recursion(int n, int k){ if(n==k)return k; int x = ...原创 2019-03-11 08:32:26 · 213 阅读 · 0 评论