————数论相关————
文章平均质量分 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 · 171 阅读 · 0 评论 -
【专题】矩阵快速幂
HDU-1757思路:这题是矩阵快速幂模板题。代码:#include <bits/stdc++.h>using namespace std;typedef long long ll;int k, mod;int num[10];struct matrix{ int m[10][10]; void init_0(){ memset(m, 0, size...原创 2019-04-09 17:00:56 · 171 阅读 · 0 评论 -
【hdu】6470 Count - 矩阵快速幂
CountTime Limit: 6000/3000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 708Accepted Submission(s): 279Problem DescriptionFarmer John有n头奶牛.某天奶牛想要数一数有多少头...原创 2019-03-29 10:15:46 · 262 阅读 · 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 · 214 阅读 · 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 · 391 阅读 · 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 · 188 阅读 · 0 评论 -
【51nod】1069 Nim游戏
1069 Nim游戏有N堆石子。A B两个人轮流拿,A先拿。每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N及每堆石子的数量,问最后谁能赢得比赛。例如:3堆石子,每堆1颗。A拿1颗,B拿1颗,此时还剩1堆,所以A可以拿到最后1颗石子。 收起输入第1行:一个数N,表示有N堆石子。(1 <...原创 2018-12-01 09:52:02 · 169 阅读 · 0 评论 -
【51nod】1066 Bash游戏
1066 Bash游戏有一堆石子共有N个。A B两个人轮流拿,A先拿。每次最少拿1颗,最多拿K颗,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N和K,问最后谁能赢得比赛。例如N = 3,K = 2。无论A如何拿,B都可以拿到最后1颗石子。输入第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)第2 ...原创 2018-12-01 09:33:49 · 126 阅读 · 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 · 240 阅读 · 0 评论 -
牛客网暑期ACM多校训练营(第二场) A - run - 动态规划
run 题解:简单的动态规划。题目提到 White Cloud 有两种移动方式① walk 1 meters per second,② run k meters per second。也就是说从次末状态到末状态有两种方式即 “walk 1 meters” 和 “run k meters” 。也就是说,我们只需要把倒退 1 meter 和 k meters 的两种状态求...原创 2018-08-28 09:49:15 · 186 阅读 · 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 · 183 阅读 · 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 · 141 阅读 · 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 · 155 阅读 · 0 评论 -
ACM-ICPC 2016 Qingdao Preliminary Contest - Problem.E Balanced Game
ACM-ICPC 2016 Qingdao Preliminary Contest #include <cstdio>using namespace std;int main(){ int t, n; scanf("%d", &t); while(t--){ scanf("%d", &n); if(n...原创 2018-08-26 13:12:53 · 200 阅读 · 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 · 322 阅读 · 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 · 212 阅读 · 0 评论 -
【专题】莫比乌斯反演
问题引入:给定整数 N 和 M。求满足且为质数的点对的个数。数据范围:接下来会见到以下内容:莫比乌斯函数 莫比乌斯函数的线性筛 迪利克雷卷积介绍 莫比乌斯反演 整除分块 杜教筛介绍莫比乌斯函数:这里 else 是指:n有大于1的平方因子的情况,如,4、9、16等。莫比乌斯函数的线性筛:其实,莫比乌斯函数线性筛与普通的线性...原创 2019-04-16 21:01:26 · 1465 阅读 · 1 评论