数论
文章平均质量分 63
Grit_ICPC
Dielts
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Light oj 1010 - Knights in Chessboard
1010 - Knights in Chessboard PDF (English)StatisticsForumTime Limit: 1 second(s)Memory Limit: 32 MBGiven an m x n chessboard where you want to p原创 2015-08-15 18:41:05 · 986 阅读 · 0 评论 -
POJ 3292 Semi-prime H-numbers(数筛)
题目大意:H-number指的是4*n+1的数(除4余1)。H-prime为没有H-number的因子的数,H-semi-prime为两个H-prime组成。求解1-h中的semi-prime个数。思路:我们可以像素数筛一样来晒数,起初都是H-prime所以他们的乘积都是semi-prime。然后标记,如果有标记的数那么一定是H-composites,标记为不是H-semi-prime和H-prim原创 2016-01-26 08:56:18 · 524 阅读 · 0 评论 -
浙江理工大学校赛 JugHard 4216(gcd)
比赛的时候没能明白这道题到底是什么意思- -!问水在两个杯子来回的倒,并且可以倒掉,问能不能得到想要得到的水的体积。通过分析样例可以看出,8 1 5 ,可以每次将1L的杯子倒满,然后向8L的杯子不停的倒5次。 5 3 4,可以先将5L的杯子倒满,然后向3L的倒,已有的3L水倒掉然后再将2L的杯子倒向刚原创 2015-12-21 20:32:45 · 1076 阅读 · 0 评论 -
codefoeces B 397 - On Corruption and Numbers
题目大意:在给定的区间【l,r】中能不能选出若干数(同一个数使用的次数不限)使得组成数n,每个数使用的次数不限。思路:这道题只需要判断一下n是不是在能组成区间的范围内即可。所以可以将使用的最大数量的钱和最少数量的钱算出。那么就得到一个可以凑出钱数的区间[mi*l,mi*r]。(注意再算使用最少数量的钱数时如果能r能被n整除则为n/r,否则为n/r+1 如 7 3 4最少要2个 )#原创 2016-01-02 11:03:07 · 491 阅读 · 0 评论 -
CodeForces 304A (暴力枚举间接判另一变量)
思路:就是枚举其中的两条边,判断第三条边是不是就是应该在符合规定的范围内。#include#include#include#include#include#include#define LL long long#define inf 0x3f3f3f3f#define ls l,mid,rt<<1#define rs mid+1,r,rt<<1|1#define L原创 2015-12-13 09:17:09 · 519 阅读 · 0 评论 -
FZU 1759 Super A^B mod C(数论+快速幂+欧拉函数)
思路:刚开始想直接用JAVA大数处理但是,由于再pow()中不能是大整数形的.后来才知道有个相当于降幂公式A^(B%oural(c)+oural(c))%c=A^B%c.#include #include #include #include #include #include #include #include using namespace std;typede原创 2015-10-06 20:55:46 · 542 阅读 · 0 评论 -
寻找平方数(质因子问题)
一个数组里任选两个数求可以相乘为平方数的个数,数组的数据范围为100000,其中数组数值得数据范围为1000000;示例输入1 5 1 2 3 4 12示例输出2分析:一个数可以分为若干质因子相乘, 假设一个数是a*b^2,其中a无平方因子,那它要相乘得到一个完全平方数只能乘以一个a*c^2的数 ,那么在这两个数的乘积原创 2015-09-11 22:15:36 · 1132 阅读 · 0 评论 -
大数+同余模
给定两数n,m(分别#includeusing namespace std;char a[1000],b[1000];int look(char a[] ){ int l=strlen(a); int an=0; for(int i=0; i<l; i++) { an= ((a[i]-'0')+an*10)%11;原创 2015-09-11 19:55:57 · 687 阅读 · 0 评论 -
POJ 1019 Number Sequence (循环递增序列的的第K个值)
Number SequenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 35823 Accepted: 10340DescriptionA single positive integer i is given. Write a program to fi原创 2015-08-17 16:19:02 · 2747 阅读 · 0 评论 -
HDU 3353 Not So Flat After All(数论)
大意:求出;两个数n,m中,(有定理一个数可以分为若干个素数的乘积的形式),指数的个数和差值。思路:直接素数筛,并且把指数记录下来。#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#define L __int64using namespace std;const int inf=0x3f3f3f原创 2016-03-01 17:55:04 · 517 阅读 · 0 评论 -
Codeforces Round #247 (Div. 2) B
B. Shower Linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMany students live in a dormitory. A dormitory is a who原创 2015-08-20 09:52:32 · 725 阅读 · 0 评论 -
Codeforces Round #262 (Div. 2) B. Little Dima and Equation
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.Find all integer solutions x (0 x 9) of the equation:x = b·s(x)原创 2015-08-20 21:37:03 · 786 阅读 · 0 评论 -
Codeforces Round #259 (Div. 2) B. Little Pony and Sort by Shift
One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That原创 2015-08-20 20:10:37 · 767 阅读 · 0 评论 -
Codeforces Round #125 (Div. 1) A. About Bacteria
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't原创 2015-08-21 09:15:39 · 749 阅读 · 0 评论 -
Codeforces Round #258 (Div. 2) B. Sort the Array
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an arraya consisting of ndistinct integers.Unfortunately, the size of a is too small. You want a bigger原创 2015-08-20 18:32:21 · 656 阅读 · 0 评论 -
HDOJ 4762 Cut the Cake(概率+Java)
Problem DescriptionMMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to deco原创 2015-09-09 22:14:35 · 642 阅读 · 0 评论 -
Codeforces Round #244 (Div. 2) B. Prison Transfer
B. Prison Transfertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe prison of your city has n prisoners. As the pri原创 2015-08-19 21:33:29 · 824 阅读 · 0 评论 -
POJ 3070 Fibonacci (矩阵快速幂)
这里有提供了一种求解斐波那契的高效方法,矩阵来求.结果对10000取余099999999991000000000-1Sample Output0346266875#include#include#include#define mod 10000using namespace std;void so(int a[2][2],int b[2][2原创 2015-11-23 20:35:03 · 521 阅读 · 0 评论 -
判断输入的一个整数有多少位是1,效率要高
方法一:判断有多少个1,可以将一个数不断的和1相与,之后将此数的二进制向右移动一位这样就可以判断有多少个一public int getSum(int n){int count = 0;if(n&1){count++;}return count;}方法二:一个整数减去一,然后和之前的数作与运算,会把当前整数的二进制最右边的1变成0,那么就是运算几次就有几个1原创 2017-03-03 19:58:40 · 1206 阅读 · 0 评论 -
DHU 4135 co-primer(容斥原理)
大意:求a-b中与n互质的个数。using namespace std;typedef long long ll;ll prime[70];ll m,n;void get_prime(){ for(ll i=2;i*i<=n;i++) if(n&&n%i==0) //对n进行素因数分解 { prime[m++]=i;原创 2016-04-18 16:48:59 · 402 阅读 · 0 评论 -
HDU 5667 Sequence(矩阵快速幂+费马小定理)
大意:He gives you 5 numbers n,a,b,c,p,and he will eat fn foods.But there are only p foods,so you should tell him fn mod p.Input The first line has a number,T,means testcase.Each testcase has 5 numb原创 2016-04-17 21:29:59 · 624 阅读 · 0 评论 -
HDU 5666 Segment(大数+gcd)
大意:给定一个直线方程x+y=p;(p为质数)求在第一象限围城的区域里格子的点数有多少。思路:一条直线上的格子点数为gcd(x,y),那么我们可以直接用三角形上加内的总点数减去在直线上的点数那么在直线上的点数为gcd(x,y)=gcd(x,y-x)(y>x)=gcd(x,p-y)=gcd(x,p)=1所以直线上的点数为0。 注意可能超__int64.import java.util.*;impo原创 2016-04-17 18:58:48 · 584 阅读 · 0 评论 -
百度之星 初赛2 瞬间转移 HDU 5698 (组合数+逆元)
大意:有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第n行第m列的格子有几种方案,答案对1000000007取模思路:每次都是向右下角走,然后就是S 1 1 1 1 1 1 2 3 4原创 2016-05-22 20:46:37 · 510 阅读 · 0 评论 -
给定字符的ASCIIn次幂且取膜后的数字,求原来的字符串(快速幂+打表)
显然可以打表,将所有的大小写字母或者数字求完幂取完膜后,判断是否有冲突,然后 进行数字拆分,如果没有对应的字符标记。#include<map>#include<cmath>#include<queue>#include<cmath>#include<string>#include<cstdio>#include<stack>#include<iostream>#include<cst原创 2016-04-13 17:30:44 · 548 阅读 · 0 评论 -
HDU 5651 xiaoxin juju needs help 逆元&组合数学
大意:求出一个串不通过增删组成多少个回文串。思路:有公式S (ni) !/((n1)!*(n2)!….(ni)! )=x;x就是可重复序列的最终组成不同的序列数。那么既然还有取余的问题,所以用到逆元(就是化除为乘),那么就可以用快速幂处理(参数二为mod-2).#include<map>#include<queue>#include<cmath>#include<cstdio>#includ原创 2016-03-28 10:51:14 · 501 阅读 · 0 评论 -
ZOJ 2853 Evolution (矩阵块速幂)
题目大意:有n个物种,经过m次进化,然后T代表有t行数据,每组数据i,j,p(i,j),代表物种i,到j演变的数量百分比。求第n-1种物种的最终数量。(ps:zoj最后输出要用%f- -!)思路:经历子过程最终到达最后一阶段,我们可以用矩阵优化。r[i][j]代表从i到j的数量分数。直接再进行块速幂即可。#include<map>#include<queue>#include<cmath>#i原创 2016-03-25 15:11:18 · 567 阅读 · 0 评论 -
Codeforces Round #241 (Div. 2) AGuess a number!
A. Guess a number!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA TV show called "Guess a number!" is gathering pop原创 2015-08-19 19:38:17 · 1117 阅读 · 0 评论 -
矩阵快速幂求解任意初始值f1,f2及a,b的斐波那契数列
已知递推式F(n)=a*F(n-1)+b*F(n-2),给定a,b,F(0),F(1)的值以及n,求F(n)。既然初始的f1,f2是随机的所以,先构造这俩个初始的矩阵.A:f1 0 0f2 0 01 0 0B:a b c //这里没有常熟项所以c值为01 0 00 0 1这样就构造出了已知的两个初始的矩阵然后就是用系数的矩阵B与单位矩阵连乘n-1次,原创 2015-11-24 10:49:42 · 1282 阅读 · 0 评论 -
51 nod 1103 N的倍数(鸽巢原理)
大意:一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍数。 例如:N = 8,数组A包括:2 5 6 3 18 7 11 19,可以选2 6,因为2 + 6 = 8,是8的倍数。思路:鸽巢原理,先求出前缀 和,判断是不是0,或者记录下下标,看存不存在q[i].x==q[i-1].x.#include<map>#include<queue>#include<cmath>#in原创 2016-03-22 21:43:07 · 592 阅读 · 0 评论 -
POJ 3252 Round Numbers (数论&&组合)
大意:求解n~m所有数中把十进制换成二进制中0的个数大于1的个数。思路:数据较大,指定不能直接暴力跑,根据排列组合可以进行处理。我们可以先用杨辉三角打表。 找到比当前数小并且满足num0>=num1. 那么就可以分为两种情况: 1、二进制数比当前的二进制数目少时,那么可以第一位的二进制为1,剩下的二进制进行排列组合;同时保证0的个数>=1的个数所以至少1的个数是从0开始到(i-1)/2(原创 2016-02-25 15:39:58 · 554 阅读 · 0 评论 -
拓展的欧几里得
找出一个数K满足0 输出 输出一个数K,满足0 示例输入2 3示例输出2思路:求解K*M%N=1,就等价于K*M=1%N;求K#include#include#include#include#include#include#include#define ll long long#define i原创 2015-09-07 17:15:53 · 650 阅读 · 0 评论 -
POJ 2115 C Looooops (拓展的欧几里得) 拓展的欧几里得详解
DescriptionA Compiler Mystery: We are given a C-language style for loop of typefor (variable = A; variable != B; variable += C) statement;I.e., a loop which starts by setting variable to原创 2015-08-25 20:58:11 · 648 阅读 · 0 评论 -
SDUT Fruit Ninja II (2416 积分)
大意:给定椭球的a,b,h并且b=c;其中椭球的公式为x^2/a^2+y^2/b^2+z^2/b^2=1,求沿着球心高出为h的地方切球分的两部分的最大一部分的体积。思路:S椭圆=PI*a*b;。#include<map>#include<queue>#include<cmath>#include<cstdio>#include<stack>#include<iostream>#inclu原创 2016-03-20 13:35:10 · 433 阅读 · 0 评论 -
codeforces 630 K. Indivisibility
问1~n内有多少数能被2~4中任意一个数整除。容斥原理。那么问题可以简化成四个数的容斥,即2 3 5 7,(忽略倍数的情况)。那么有公式a+b+c+d-ab-ac-ad-bc-bd-cd+abc+abd+acd+bcd-abcd#include<map>#include<queue>#include<cmath>#include<iostream>#include<cstdio>#incl原创 2016-02-19 10:37:54 · 551 阅读 · 0 评论 -
Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环结)
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:(1n + 2n + 3n + 4n) mod 5for given value of n. Fedya managed to complete the task. Can you? Note that原创 2015-08-20 20:33:18 · 570 阅读 · 0 评论 -
HDOJ 2252 三足鼎立
#include#include#include#include#include#include#define LL long long#define inf 0x3f3f3f3fusing namespace std;int main(){ int n,m,j,k; double s,u,v; scanf("%d",&n); while(n-原创 2015-08-26 21:28:19 · 547 阅读 · 0 评论 -
CodeForces 453A
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that wer原创 2015-08-22 16:46:34 · 1466 阅读 · 0 评论 -
HDOJ 5417 Victor and Machine
Problem DescriptionVictor has a machine. When the machine starts up, it will pop out a ball immediately. After that, the machine will pop out a ball everyw seconds. However, the machine has some原创 2015-08-24 09:15:45 · 769 阅读 · 0 评论 -
HDOJ 2674 N!Again(找规律)
Problem DescriptionWhereIsHeroFrom: Zty, what are you doing ?Zty: I want to calculate N!......WhereIsHeroFrom: So easy! How big N is ?原创 2015-08-26 19:45:25 · 644 阅读 · 0 评论 -
HDOJ 1097 A hard puzzle(循环节||快速幂)
Problem Descriptionlcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.原创 2015-08-26 19:16:12 · 963 阅读 · 0 评论
分享