数学
追风者_
要我自我介绍,挺秃然的
展开
-
【HDU 1005】 Number Sequence 周期
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).InputThe input consists of multiple test cases. Each test case contains 3 integers A, B and原创 2020-08-07 01:15:06 · 145 阅读 · 0 评论 -
【SCAU 10新生赛】 9511 跑跑卡丁车I 数论
某年暑假的时候,QIU很喜欢玩跑跑卡丁车,因为跑跑卡丁车能够在线联网,所以他就能跟自己的朋友一齐很开心的在同一跑道上比赛。跑跑卡丁车的地图很多样,但是模式都差不多,在道具模式中,我们可以得到一些很有利的道具,帮助我们尽快的到达终点,或者妨碍对手前进。为了简化模型,我们假设地图上只有一种道具(金币),如果你检了的话,你就可以增加自己的财富(¥¥),而地图中通常都有很多个点,很多条路,每个点上存在不同的金币数量(不过捡了就没了),当你钱包的金币数达到一定的数量时,你就可以利用这些金币买到你喜欢的东西了_。原创 2020-08-04 17:45:32 · 293 阅读 · 0 评论 -
【AcWing 198】 反素数 dfs 数论
对于任何正整数x,其约数的个数记作g(x),例如g(1)=1、g(6)=4。如果某个正整数x满足:对于任意的小于x的正整数 i,都有g(x)>g(i) ,则称x为反素数。例如,整数1,2,4,6等都是反素数。现在给定一个数N,请求出不超过N的最大的反素数。输入格式一个正整数N。输出格式一个整数,表示不超过N的最大反素数。数据范围1≤N≤2∗109输入样例:1000输出样例:840题意:如题思路:依照题意,不难得出x是【1,x】中约数个数最大的那个,而且其中没有个数相等的原创 2020-08-03 20:51:15 · 183 阅读 · 0 评论 -
【牛客多校 #7】 H Dividing 整数分块
链接:https://ac.nowcoder.com/acm/contest/5672/H来源:牛客网The following rules define a kind of integer tuple - the Legend Tuple:(1, k) is always a Legend Tuple, where k is an integer.if (n, k) is a Legend Tuple, (n + k, k) is also a Legend Tuple.if (n, k) is原创 2020-08-01 19:31:23 · 341 阅读 · 0 评论 -
【暑训排位赛 #C】Gym - 100952D 简单组合
You have been out of Syria for a long time, and you recently decided to come back. You remember that you have M friends there and since you are a generous man/woman you want to buy a gift for each of them, so you went to a gift store that have N gifts, eac原创 2020-07-10 18:22:38 · 175 阅读 · 0 评论 -
【暑训排位 #9 F】 思维
You are given a permutation p of length n. Also you are given m foe pairs (a i, b i) (1 ≤ a i, b i ≤ n, a i ≠ b i).Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn’t count int原创 2020-07-08 17:45:35 · 192 阅读 · 0 评论 -
【SCAU 14年新生赛】17976 wzhp也想找女朋友 容斥定理 dfs
Description最近,wzhp身边有许多好朋友得到真爱。看着好朋友与妹子成双成对,Wzhp也嫉妒起来了,他也想找个女朋友,所以他在他们班上举办了一次联谊晚会,希望能找到女票。已知有好多个女生参加这次联谊晚会,把这些女生从1到N-1编号,其中N为wzhp的编号,经过一个晚上的happy聚会,wzhp看上了好多美女,他把这些女生的编号都记下来了。X神很好奇的想知道wzhp看上多少位女生,于是他暗地里去了解,但他惊奇的发现,不被看上的女生的编号和wzhp的编号都有大于1的公约数。但由于女生实在原创 2020-07-07 00:05:01 · 262 阅读 · 0 评论 -
【暑训排位 #6 B】 排列组合
N boxes are lined up in a sequence (1 ≤ N ≤ 20). You have A red balls and B blue balls (0 ≤ A ≤ 15, 0 ≤ B ≤ 15). The red balls (and the blue ones) are exactly the same. You can place the balls in the boxes. It is allowed to put in a box, balls of the two k原创 2020-07-05 21:53:42 · 360 阅读 · 0 评论 -
【HDU 1576】 A/B 费马小定理 or 欧几里得扩展
Problem Description要求(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 Input21000 5387 123456789Sample Output7922606原创 2020-07-04 11:12:04 · 330 阅读 · 0 评论 -
【HDU 4704】 Sum 费马小定理
题意:将n依次分割成1->n块,每块和为n,问共有多少种分法。思路:隔板法,分割成k块的时候,即是n-1个间隙里放入k-1个隔板。C(k-1,n-1),累加,利用二项式定理即是求2n-1。但是由于n太大,需要用费马小定理降幂。因为2和p互质,那么2p-1和1对p同余,那我们看2n-1能分出多少个2p1,这部分利用同余定理就都变成乘1,只需要求出2(n-1)%(mod-1)即可,指数在1e9+8以内,这个时候利用快速幂就可以快速求出来了AC代码:#include<iostream>.原创 2020-07-04 09:58:30 · 256 阅读 · 0 评论 -
【暑训排位 #4 G】 欧几里得扩展
The number x is called an idempotent modulo n ifx* x = x (mod n)Write the program to find all idempotents modulo n, where n is a product of two distinct primes p and q.InputFirst line contains the number k of test cases to consider (1 ≤ k ≤ 1000). Each原创 2020-07-03 21:20:40 · 125 阅读 · 0 评论 -
【暑训个人赛#2 E】 HDU - 4135 容斥定理 唯一分解定理
Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than 1 or, equivalently, if t原创 2020-06-26 18:16:11 · 183 阅读 · 0 评论 -
【Codeforces】GCD Compression 唯一分解定理 思维
Ashishgup and FastestFinger play a game.They start with a number n and play in turns. In each turn, a player can make any one of the following moves:Divide n by any of its odd divisors greater than 1.Subtract 1 from n if n is greater than 1.Divisors of原创 2020-06-23 12:02:54 · 386 阅读 · 0 评论 -
【CodeForces 782B】 The Meeting Place Cannot Be Changed 二分
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road there are n friends, and i-th of them is standing at the原创 2020-06-22 12:35:31 · 151 阅读 · 0 评论 -
【CodeForces 577C】 唯一分解定理
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.Petya can ask questions like: “Is the unknown number divisible by number y?”.The game is played by the following rules: first Petya原创 2020-06-22 11:13:16 · 427 阅读 · 0 评论 -
【CodeForces 577B】 Modulo Sum 鸽巢(抽屉)原理 DP
You are given a sequence of numbers a1, a2, …, an, and a number m.Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.InputThe first line contains two numbers, n and m (1 ≤ n ≤原创 2020-06-21 23:52:22 · 419 阅读 · 0 评论 -
【CodeForces 682A 】Alyona and Numbers 思维
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how m原创 2020-06-20 22:15:31 · 329 阅读 · 0 评论 -
【CodeForces 304A 】Pythagorean Theorem II 高斯素数 高效算法
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:In any right-angled triangle, the area of the square whose side is the hypotenuse (the side oppos原创 2020-06-19 15:49:49 · 326 阅读 · 0 评论 -
【SCAU 13校赛】 17110 Divisible 唯一分解定理 or 同余定理
DescriptionGiven n + m integers, I1,I2,…,In,T1,T2,…,Tm, we want to know whether (I1I2…In)%(T1T2*…*Tm)= =0.输入格式The first line gives two integers n and m. 1<=n,m<=100The second line gives n integers I1 I2 … In.The third line gives m integers T1 T2原创 2020-06-13 16:37:36 · 444 阅读 · 0 评论 -
【SCAU 14校赛C】 18001 Farmer Cat 数论
DescriptionThere are a lot of bulls in SCAU. One of them loves eating fodder. But his owner – Farmer Cat would not allow him to eat too much fodder, so she plays a game with this bull.This game is about A SIMPLE MATH PROBLEM : A number between 1 to 230 w原创 2020-06-13 15:24:11 · 170 阅读 · 0 评论 -
【SCAU 14校赛】17998 Equality 签到题 注意亿点细节
DescriptionDo you know the problem “Divisible” in SCAUCPC 2013? No? It does not matter. Today, I will introduce a similar thing to you.You are given N numbers to multiply into a single number A, and another M numbers into number B.However, because WJMKQ原创 2020-06-12 23:16:47 · 267 阅读 · 0 评论 -
【SCAU 16校赛】 18108 规律 O(n)法 预处理
DescriptionChocola is addicted to a phone game named white grid. There’s a cross with 5 empty grids on the game interface.Chocola can write 5 different numbers ranging between 1 and n (inclusive) into grids.When the sum of 3 horizontal grids is equal to原创 2020-06-12 15:35:19 · 188 阅读 · 0 评论 -
【SCAU 16校赛】 18112 Play Ball 物理 最短路 floyd
DescriptionOne day, Xiaoming and his friends want to play the basketball, but there are not basketball court nearby. So theycome out with a new idea to play game. At the beginning, Xiaoming hold the ball, and he throw the ball to one of hisfriends, and原创 2020-06-12 11:19:31 · 170 阅读 · 0 评论 -
【AcWing 97】 约数之和 唯一分解定理 + 分治 + 快速幂
假设现在有两个自然数A和B,S是AB的所有约数之和。请你求出S mod 9901的值是多少。输入格式在一行中输入用空格隔开的两个整数A和B。输出格式输出一个整数,代表S mod 9901的值。数据范围0≤A,B≤5×107输入样例:2 3输出样例:15注意: A和B不会同时为0。题意:如题思路:首先我们得知道唯一分解定理求因数和的公式(分解a)Ans = (q10+q11+q12 …q1a1)·(q20+q21+q22…q2a2)…(qn0+qnn+qn2…qnan)其中q原创 2020-05-21 14:07:37 · 238 阅读 · 0 评论 -
【POJ 1730】 Perfect Pth Powers 唯一分解定理 枚举
DescriptionWe say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, for some integer b, x = b3. More generally, x is a perfect pth power if, for some integ...原创 2020-05-06 18:42:07 · 343 阅读 · 0 评论 -
【POJ 2739】 Sum of Consecutive Prime Numbers 前缀和预处理 打表 线性筛
DescriptionSome positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 h...原创 2020-05-06 15:26:16 · 171 阅读 · 0 评论 -
【HDU 2098】 分拆素数和 线性筛
Problem Description把一个偶数拆成两个不同素数的和,有几种拆法呢?Input输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。Output对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。Sample Input30260Sample Output32思路(线性筛):模板题,套线性筛的板子,先打表,然后遍历2-&g...原创 2020-05-06 13:49:28 · 191 阅读 · 0 评论 -
【HDU 1215】 七夕节 唯一分解定理 素数 数论
七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:“你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!”人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6.你想知道你的另一半吗?Input输入数据的第一行是一个数字T(1<=T<=500000),它...原创 2020-05-06 12:58:02 · 303 阅读 · 0 评论 -
【校队排位赛#13 J】 A Dangerous Maze 概率
You are in a maze; seeing n doors in front of you in beginning. You can choose any door you like. The probability for choosing a door is equal for all doors.If you choose the ith door, it can either ...原创 2020-04-05 17:58:27 · 123 阅读 · 0 评论 -
【校队排位赛#13 I】 Paths on a Grid 简单组合问题 + 细节处理
Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he’s explaining that (a+b) 2=a 2+2ab+b ...原创 2020-04-05 17:11:32 · 228 阅读 · 0 评论 -
【校队排位赛#11 A】 Friend or Girlfriend basic 数学
Shlok and Sachin are good friends. Shlok wanted to test Sachin, so he wrote down a string S with length N and one character X. He wants Sachin to find the number of different substrings of S which con...原创 2020-03-28 20:19:34 · 266 阅读 · 0 评论 -
【模板】矩阵快速幂 洛谷 P3390
题目背景矩阵快速幂题目描述给定 n\times nn×n 的矩阵 AA,求 A^kAk。输入格式第一行两个整数 n,kn,k 接下来 nn 行,每行 nn 个整数,第 ii 行的第 jj 的数表示 A_{i,j}Ai,j 。输出格式输出 A^kAk共 nn 行,每行 nn 个数,第 ii 行第 jj 个数表示 (A^k)_{i,j}(Ak)i,j ,每个元...原创 2020-03-27 00:43:36 · 430 阅读 · 0 评论 -
【校队排位赛#2 A】 数学 签到题
题意:在数值差距最大的条件下可以凑出多少对数其实也没啥好讲的,排个序,找出最大的有多少个,最小的有多少个,相乘一下就好了。如果最大最小一样的话就是组合数nx(n-1)/2就行了。#include <iostream>#include <vector>#include <cstdio>#include <map>#include <...原创 2020-02-23 20:23:22 · 243 阅读 · 0 评论 -
【校队排位赛#10 B】 The Same Calendar 基础 周期
The Same Calendartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe girl Taylor has a beautiful calendar for the year y. In the calendar all ...原创 2020-03-22 17:55:32 · 326 阅读 · 0 评论 -
【校队排位赛#10 J】Duff in Love 数论
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.Malek has a number store! In his st...原创 2020-03-22 17:35:28 · 214 阅读 · 0 评论 -
【校队排位赛#7 H】 HDU NPY and girls 莫队算法 + 费马小定理 + 快速幂
NPY and girlsTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2776 Accepted Submission(s): 896Problem DescriptionNPY’s girlfriend blew him...原创 2020-03-16 23:45:45 · 215 阅读 · 0 评论 -
【校队排位赛#6 H】 CodeForces - 736B Taxes 哥德巴赫猜想
B. Taxestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Funt now lives in a country with a very specific tax laws. The total income of mr...原创 2020-03-08 20:12:34 · 261 阅读 · 0 评论