
英雄哥夜深人静写算法做题笔记
文章平均质量分 55
本专栏是英雄哥夜深人静写算法专栏部分题目的代码演示。
憨憨少年不想秃头
这个作者很懒,什么都没留下…
展开
-
The Luckiest number(二分快速幂+欧拉函数)
DescriptionChinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own lucky numberL. Now he wants to construct his luckiest number which is the minimum among all positive integers that are a multiple ofLand con...原创 2021-12-06 12:56:55 · 152 阅读 · 0 评论 -
Longge‘s problem(欧拉函数的应用+因式枚举)
DescriptionLongge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N.原创 2021-11-22 13:33:02 · 304 阅读 · 0 评论 -
Become A Hero(欧拉函数预选筛+素数筛)
Problem DescriptionLemon wants to be a hero since he was a child. Recently he is reading a book called “Where Is Hero From” written by ZTY. After reading the book, Lemon sends a letter to ZTY. Soon he recieves a reply.Dear Lemon,It is my way of success原创 2021-11-21 11:00:55 · 220 阅读 · 0 评论 -
Problem D. Euler Function(欧拉函数的性质)
Problem DescriptionIn number theory, Euler's totient functionφ(n)counts the positive integers up to a given integernthat are relatively prime ton. It can be defined more formally as the number of integerskin the range1≤k≤nfor which the greatest ...原创 2021-11-21 10:20:07 · 368 阅读 · 0 评论 -
Find the maximum(素数筛+高精度乘法+二分+欧拉函数性质分析)
Problem DescriptionEuler's Totient function, φ (n) [sometimes called the phi function], is used to determine the number of numbers less than n which are relatively prime to n . For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively p原创 2021-11-20 16:52:44 · 286 阅读 · 0 评论 -
The Euler function(欧拉函数预处理+素数筛+一维数组求前缀和)
DescriptionThe 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 areF2 = {1/2}F3 = {1/3, 1/2, 2/3}F4 = {1/4, 1/3,原创 2021-11-19 13:55:55 · 306 阅读 · 0 评论 -
The Euler function(欧拉函数预处理+素数筛+一维数组前缀和)
Problem DescriptionThe Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very e原创 2021-11-18 15:20:02 · 368 阅读 · 0 评论 -
GCD Again
Problem DescriptionDo you have spent some time to think and try to solve those unsolved problem after one ACM contest?No? Oh, you must do this when you want to become a "Big Cattle".Now you will find that this problem is so familiar:The greatest commo原创 2021-11-18 14:55:05 · 74 阅读 · 0 评论 -
找新朋友(欧拉函数+素数筛预选处理)
Problem Description新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。Input第一行是测试数据的组数CN(Case number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。Output对于每一个N,原创 2021-11-18 14:41:46 · 224 阅读 · 2 评论 -
Relatives(素数筛+欧拉函数)
DescriptionGiven n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.InputThere are sever原创 2021-11-18 14:18:27 · 207 阅读 · 0 评论 -
小明系列故事——师兄帮帮忙
Problem Description 小明自从告别了ACM/ICPC之后,就开始潜心研究数学问题了,一则可以为接下来的考研做准备,再者可以借此机会帮助一些同学,尤其是漂亮的师妹。这不,班里唯一的女生又拿一道数学题来请教小明,小明当然很高兴的就接受了。不过等他仔细读题以后,发现自己也不会做,这下小明囧了:如果回复说自己不懂,岂不是很没面子? 所以,他现在私下求你帮忙解决这道题目,题目是这样的: 给你n个数字,分别是a1,a2,a3,a4,a5……an,这些数字每过一个单位时间就会改变,假设上一原创 2021-11-17 21:31:57 · 139 阅读 · 0 评论 -
Pupu(二分快速幂)
Problem DescriptionThere is an island called PiLiPaLa.In the island there is a wild animal living in it, and you can call them PuPu. PuPu is a kind of special animal, infant PuPus play under the sunshine, and adult PuPus hunt near the seaside. They fell原创 2021-11-17 18:54:33 · 208 阅读 · 0 评论 -
Pseudoprime numbers
DescriptionFermat's theorem states that for any prime numberpand for any integera> 1,ap=a(modp). That is, if we raiseato thepthpower and divide byp, the remainder isa. Some (but not very many) non-prime values ofp, known as base-apseu...原创 2021-11-17 10:17:50 · 505 阅读 · 0 评论 -
Raising Modulo Numbers
DescriptionPeople are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this原创 2021-11-16 22:23:49 · 143 阅读 · 0 评论 -
P1226 【模板】快速幂||取余运算
题目描述给你三个整数a,b,pa,b,p,求a^b \bmod pabmodp。输入格式输入只有一行三个整数,分别代表a,b,pa,b,p。输出格式输出一行一个字符串a^b mod p=s,其中a,b,pa,b,p分别为题目给定的值,ss为运算结果。输入输出样例输入 #12 10 9输出 #12^10 mod 9=7说明/提示样例解释2^{10} = 1024210=1024,1024 \bmod 9 = 71024mod9=7。...原创 2021-11-16 22:03:23 · 573 阅读 · 0 评论 -
Rightmost Digit(循环节快速幂)
Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N.InputThe input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.Eac原创 2021-11-16 21:58:35 · 246 阅读 · 0 评论 -
人见人爱A^B
Problem Description求A^B的最后三位数表示的整数。 说明:A^B的含义是“A的B次方”Input输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。Output对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。Sample Input2 3 12 6 6789 10000 0 0Sample Output8 984 1原创 2021-11-16 21:49:47 · 81 阅读 · 0 评论