数论
Hanylch
菜鸟的起飞之路
Think and Practice
展开
-
扩展欧几里得算法
扩展欧几 ax + by = gcd( a,b ) = n int extgcd(int a,int b,int &x,int &y){ int d = a; if( b != 0) { d = extgcd(b,a % b,y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d原创 2017-03-18 20:18:28 · 203 阅读 · 0 评论 -
Trailing Zeroes (III) LightOJ - 1138 (数论,求n! 中某个数的个数)
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*…*N. For example, 5! = 120, 120 contains one zero on the trail.原创 2017-04-06 16:22:36 · 385 阅读 · 0 评论 -
蓝桥杯 算法训练 Hankson的趣味题 (唯一分解定理)
算法训练 Hankson的趣味题 时间限制:1.0s 内存限制:64.0MB 提交此题 锦囊1 锦囊2 问题描述 Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson。现 在,刚刚放学回家的Hankson 正在思考一个有趣的问题。 今天在课堂上,老师讲解了如何求两个正整数c1 和c2 的最大公约数和最小公倍数。现 在Hankson原创 2017-05-02 18:53:19 · 943 阅读 · 1 评论 -
青蛙的约会 POJ - 1061 (拓展欧几里得算法)
两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你原创 2017-04-20 15:51:03 · 440 阅读 · 0 评论 -
Maximum GCD UVA - 11827 (gcd ,输入)
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible pair of these integers. Input The first line of input is an integer N (1 < N < 100) that determines原创 2017-04-20 17:49:10 · 342 阅读 · 0 评论 -
Farey Sequence POJ - 2478(欧拉函数)
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are F2 = {1/2} F3原创 2017-04-25 21:42:19 · 190 阅读 · 0 评论 -
The Super Powers UVA - 11752 (素数分解)
We all know the Super Powers of this world and how they manage to get advantages in political warfare or even in other sectors. But this is not a political platform and so we will talk about a differe原创 2017-04-25 21:47:51 · 289 阅读 · 0 评论 -
Prime Time UVA - 10200(打表)
Euler is a well-known matematician, and, among many other things, he discovered that the formula n 2 + n + 41 produces a prime for 0 ≤ n < 40. For n = 40, the formula produces 1681, which is 41 ∗ 41.原创 2017-04-27 21:37:28 · 282 阅读 · 0 评论 -
Help Hanzo LightOJ - 1197
Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After hea原创 2017-04-06 11:45:08 · 266 阅读 · 0 评论 -
Colliders CodeForces - 154B(分解素数)
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating sev原创 2017-04-14 20:07:37 · 373 阅读 · 0 评论 -
Mysterious Bacteria LightOJ - 1220 (唯一分解定理,gcd)
Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 has a very strange reproduction system. RC-01 lives exactly x days. Now RC-01 produces exactly p new deadly Bacteria where x = b原创 2017-04-04 20:13:32 · 207 阅读 · 0 评论 -
Aladdin and the Flying Carpet LightOJ - 1341 (算术基本定理)
Aladdin and the Flying Carpet LightOJ - 1341 It’s said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first原创 2017-04-02 21:12:14 · 246 阅读 · 0 评论 -
Sigma Function LightOJ - 1336 (打表找规律)
Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum of all divisors of a number. For example σ(24) = 1+2+3+4+原创 2017-04-03 14:54:22 · 308 阅读 · 0 评论 -
Leading and Trailing LightOJ - 1282 (n^k 的前三个数)
You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.Input Input starts with an integer T (≤ 1000), denoting the number原创 2017-04-03 16:11:48 · 369 阅读 · 0 评论 -
Goldbach`s Conjecture LightOJ - 1259 (素数筛选法)
Goldbach’s conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:Every even integer, greater than 2, can be expressed as the sum of two primes [1].Now原创 2017-04-03 16:56:30 · 306 阅读 · 0 评论 -
GCD - Extreme (II) UVA - 11426 (欧拉函数)
题目链接/* 看了挺久的,才大致看懂了是什么意思; 要求给定数的gcd(i,j) (1<=i<=j<=n) 因为数据很大,故打表是个选择 对于给定的n, a(n) = gcd(1,n)+gcd(2,n) +......+gcd(n-1,n) 故 结果为 sum(n) = a(2) + a(3) + a(4) + ...... + a(n); sum原创 2017-04-12 20:08:31 · 270 阅读 · 0 评论 -
Harmonic Number (II) LightOJ - 1245 (找规律)
I was trying to solve problem ‘1234 - Harmonic Number’, I wrote the following codelong long H( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) res = res + n / i; retu原创 2017-04-04 14:49:00 · 902 阅读 · 0 评论 -
Harmonic Number LightOJ - 1234 (暴力打表,区域保存)
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers。Hn = 1 + 1 / 2 +1/3 +…… + 1/nIn this problem, you are given n, you have to find Hn.Input Input star原创 2017-04-04 15:39:54 · 302 阅读 · 0 评论 -
Pairs Forming LCM LightOJ - 1236 (算术定理)
Find the result of the following code:long long pairsFormLCM( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) for( int j = i; j <= n; j++ ) if( lcm(i, j) == n原创 2017-04-04 16:37:44 · 276 阅读 · 0 评论 -
Bi-shoe and Phi-shoe LightOJ - 1370(欧拉函数+技巧)
Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go原创 2017-04-27 21:39:41 · 260 阅读 · 0 评论