数论只会GCD
UncleJokerly
Tough days don't last.Tough people do.
展开
-
求两数的最大公约数与最小公倍数
问题描述 输入两个正整数m和n,求其最大公约数和最小公倍数。(如输入8 12,输出最大公约数为4,最小公倍数为24) 代码如下:#include<stdio.h>int main(){ int m,n,t,b,c; scanf("%d%d",&m,&n); if(m<n) { t=m; m=n; n=t;原创 2016-12-20 21:49:07 · 680 阅读 · 0 评论 -
2013年第四届蓝桥杯C/C++程序设计本科B组省赛 黄金连分数(结果填空)
标题: 黄金连分数 黄金分割数0.61803... 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。 对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工错误,对那样一个庞然大物,其实只是镜面加工时有比头发丝还细许多倍的一处错误而已,却使它成了“近视眼”!! 言归正传,我们如何求得黄...原创 2019-03-19 19:42:29 · 420 阅读 · 0 评论 -
HDU5584 LCM Walk(数论)
A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. Now the frog is sitting on a grid map of infinite rows and columns. Rows are numbered 1,2,⋯1,2,⋯ from...原创 2018-11-20 15:56:02 · 300 阅读 · 0 评论 -
FZU - 2278 YYS(期望)
Yinyangshi is a famous RPG game on mobile phones.Kim enjoys collecting cards in this game. Suppose there are n kinds of cards. If you want to get a new card, you need to pay W coins to draw a card. Ea...原创 2018-05-05 21:47:14 · 340 阅读 · 1 评论 -
FZU - 2282 Wand(排列组合+错排+费马小定理求逆元+快速幂)
N wizards are attending a meeting. Everyone has his own magic wand. N magic wands was put in a line, numbered from 1 to n(Wand_i owned by wizard_i). After the meeting, n wizards will take a wand on...原创 2018-05-05 20:33:46 · 303 阅读 · 0 评论 -
POJ3070 Fibonacci(矩阵快速幂求斐波那契数列数列)
In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …An alternative f...原创 2018-04-27 11:33:02 · 424 阅读 · 0 评论 -
FZU2268 Cutting Game(数论&规律)
Fat brother and Maze are playing a kind of special (hentai) game with a piece of gold of length N where N is an integer. Although, Fat Brother and Maze can buy almost everything in this world (except ...原创 2018-04-26 08:12:56 · 336 阅读 · 0 评论 -
FZU2265 Card Game (Second Edition)(数论&规律)
Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card deck. The game goes for N rounds and in ...原创 2018-04-25 20:51:31 · 488 阅读 · 0 评论 -
FZU2264 Card Game (First Edition)(数论&规律)
Fat brother and Maze are playing a kind of special (hentai) game with some cards. There are N*2 cards in this game for the players to use, this is the card deck. The game goes for N rounds and in each...原创 2018-04-25 19:54:46 · 320 阅读 · 0 评论 -
2018ACM-ICPC中国大学生程序设计竞赛线上赛I. Reversion Count(数论&规律)
题目链接:https://nanti.jisuanke.com/t/2621726.87% 1000ms 65536KDescription:There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1234, Y=4321. Z=(X-Y)/9,Judge...原创 2018-04-23 08:29:43 · 2284 阅读 · 0 评论 -
2017年第八届蓝桥杯C/C++程序设计本科B组省赛 等差素数列(结果填空)(素数筛)
标题:等差素数列2,3,5,7,11,13,....是素数序列。类似:7,37,67,97,127,157 这样完全由素数组成的等差数列,叫等差素数数列。上边的数列公差为30,长度为6。2004年,格林与华人陶哲轩合作证明了:存在任意长度的素数等差数列。这是数论领域一项惊人的成果!有这一理论为基础,请你借助手中的计算机,满怀信心地搜索:长度为10的等差素数列,其公差最小值是多少?注意:需要提交的是...原创 2018-03-29 10:14:10 · 473 阅读 · 0 评论 -
快速幂运算模板(求n^k以及前几位或后几位)
计算n^k的结果步骤:1.把n由十进制转换为二进制,按二进制来计算(最后结果还是一样的)2.把n由二进制转换为2^k相加的形式先举个例子:求5^22:接着就可以很好地理解了O(logn)计算幂运算的算法://无mod单纯求n^k #include<stdio.h>typedef long long ll;ll mod_pow(ll x,ll n){ ll res=1;...原创 2018-03-30 17:43:47 · 1590 阅读 · 2 评论 -
素数筛法打表模板
没有分析几种模板的效率,先记下一个用着吧#include<stdio.h>#include<string.h>#define MAXX 1000//求MAXX范围内的素数 int prime[MAXX+5],len=0;int p[MAXX+5];//p设为bool型较为合适,但int结果也对,注意把p数组加大一点防止越界 //思想:将范围内的合数全部筛掉剩余...原创 2018-03-30 10:25:38 · 300 阅读 · 0 评论 -
HDU1999 不可摸数(数论)(筛法打表)
s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何 数m,s(m)都不等于n,则称n为不可摸数. Input包含多组数据,首先输入T,表示有T组数据.每组数据1行给出n(2<=n<=1000)是整数。Output如果n是不可摸数,输出yes,否则输出noSample Input3258Sample Outputyesye...原创 2018-03-30 09:18:18 · 470 阅读 · 0 评论 -
HDU1023 Train Problem (卡特兰数)
As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railwa...原创 2017-06-08 20:33:34 · 413 阅读 · 0 评论 -
HDU1576 A/B(扩展欧几里得)
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。 Input 数据的第一行是一个T,表示有T组数据。 每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。 Output 对应每组数据输出(A/B)%9973。 Sample Input 2...原创 2017-06-03 10:57:59 · 450 阅读 · 0 评论 -
HDU1005 Number Sequence(思维&规律)
problem: A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input The input consists原创 2017-02-22 20:25:25 · 344 阅读 · 0 评论 -
HDU 1394 Minimum Inversion Number(线段树求逆序数)
The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj.For a given sequence of numbers a1, a2, ..., an, if we move the f...原创 2019-04-23 15:30:11 · 235 阅读 · 0 评论