
数论~数论
哇-WA
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
欧拉函数【模板】
欧拉函数:欧拉函数是小于n的正整数中与n互质的数的数目(φ(1)=1)。直接求欧拉函数: int euler(int n){ //返回euler(n) int res=n,a=n; for(int i=2;i*i<=a;i++){ if(a%i==0){ res=res/i*(i-1);//先进行...原创 2017-08-16 09:53:14 · 328 阅读 · 0 评论 -
CKOJ 1072: 简单的问题【组合数学】
1072: 简单的问题时间限制: 1 Sec 内存限制: 128 MB提交: 21 解决: 5[提交][状态][讨论版]题目描述这个问题太简单了以至于出题人想不到什么捏造什么背景了(脑洞缺失那就让我们直奔主题吧:给你一个n,你能否知道,在[0,n)中,有多少数的二进制表示中1的个数和n的二进制表示中1的个数是一样多的?输入:第一行一个T,表示有T组数据其后T行,每行一个整数,代表n输出:n行每...原创 2018-04-13 09:56:57 · 436 阅读 · 0 评论 -
2018 ACM-ICPC B. Goldbach【java快速判断素数】
Description:Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states:Every even integer greater than 2 can be expressed as the sum...原创 2018-04-23 14:04:28 · 211 阅读 · 0 评论 -
素数判定的一些讨论(Miller-Rabin算法)
很久没有写博客了。。。最近军训加开学,感觉刷题速度有降低,要补一补。回归正题,正式进入数论阶段,讨论一下关于素数判定的那些事。一类问题: 判定一个整数n(n>1)是否为素数。Miller-Rabin算法:这是一种随机性素数判定算法,也就是说,答案可能出错,但是可能性极小。先是讲两个定理:费马小定理: 对于一个质数pp,取任意整数aa,满足gcd(p,a)=1gcd(p,a)=1,则有 ap−...转载 2018-04-24 17:52:29 · 742 阅读 · 0 评论 -
CodeForces - 546D Soldier and Number Game【素数筛+前缀和】
D. Soldier and Number Gametime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo soldiers are playing a game. At the beginning first of them chooses ...原创 2018-05-03 09:42:00 · 226 阅读 · 0 评论 -
FZU - 2278 YYS 【期望+java大数】
Problem 2278 YYSAccept: 177 Submit: 475Time Limit: 1000 mSec Memory Limit : 262144 KB Problem DescriptionYinyangshi is a famous RPG game on mobile phones.Kim enjoys collecting cards in this gam...原创 2018-05-05 21:28:42 · 236 阅读 · 0 评论 -
南昌大学航天杯第二届程序设计竞赛校赛 F 阿汤的疑惑【分解素因子】
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld题目描述 阿汤同学最近刚学数论,他发现数论实在是太有趣了,于是他想让你也感受一下数论的乐趣。现在他给你一个正整数 N 和一个正整数 M,要求你用 N 对 M 进行取余操作,即 N % M,记余数为 S。但是他发现这样好像并不能让你感受到数论的乐趣,于是他想让你在...原创 2018-05-22 15:01:27 · 254 阅读 · 0 评论 -
LightOJ - 1027 A Dangerous Maze【期望】
A Dangerous Maze LightOJ - 1027 思路:走出来的期望时间 = 需要走次数的期望*平均走一次花费的时间代码:#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<vector>#include&...原创 2018-06-05 21:50:08 · 149 阅读 · 0 评论 -
Educational Codeforces Round 49 (Rated for Div. 2) C. Minimum Value Rectangle
C. Minimum Value Rectangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have nn sticks of the given lengths.Your task is...原创 2018-08-19 13:25:35 · 194 阅读 · 0 评论 -
计蒜客-Exponial【快速幂+欧拉降幂】
Everybody loves big numbers (if you do not, you might want to stop reading at this point). There are many ways of constructing really big numbers known to humankind, for instance:In this problem w...原创 2018-08-24 17:53:10 · 361 阅读 · 0 评论 -
nyoj-1007 GCD【欧拉函数】
GCD时间限制:1000 ms | 内存限制:65535 KB难度:3输入The first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (1<=...原创 2018-09-26 21:37:30 · 224 阅读 · 0 评论 -
Wannafly挑战赛25 A 因子
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述 令 X = n!, 给定一大于1的正整数p 求一个k使得 p ^k | X 并且 p ^(k + 1) 不是X的因子。输入描述:两个数n, p (1e18>= n>= 10000 >= p >= 2)...原创 2018-09-29 10:14:25 · 294 阅读 · 2 评论 -
逆元【模板】
参考:https://blog.youkuaiyun.com/baidu_35643793/article/details/75268911费马小定理求逆元 O(logn):const int mod = 1000000009;long long quickpow(long long a, long long b) { if (b < 0) return 0; long lo...原创 2018-09-29 19:49:55 · 1284 阅读 · 0 评论 -
2017-2018 ACM-ICPC ECL-Final 2017 A. Chat Group【组合数+逆元】
A. Chat Grouptime limit per test1.0 smemory limit per test256 MBinputstandard inputoutputstandard outputIt is said that a dormitory with 6 persons has 7 chat groups ^_^. But the numb...原创 2018-11-21 16:42:12 · 283 阅读 · 0 评论 -
SCU - 4489 misaka and last order【枚举因子】
Time Limit: 1000 MS Memory Limit: 131072 K DescriptionMisaka Mikoto is a main character of the Animation "To Aru Majutsu no Index" and "To Aru Kagaku no Railgun". She was enrolled into t...原创 2018-04-18 17:05:27 · 363 阅读 · 0 评论 -
计蒜客-天上的星星【前缀和+容斥】
在一个星光摧残的夜晚,蒜头君一颗一颗的数这天上的星星。蒜头君给在天上巧妙的画了一个直角坐标系,让所有的星星都分布在第一象。天上有 nn 颗星星,他能知道每一颗星星的坐标和亮度。现在,蒜头君问自己 qq 次,每次他问自己每个矩形区域的星星的亮度和是多少(包含边界上的星星)。输入格式第一行输入一个整数 n(1 \le n \le 50000)n(1≤n≤50000) 表示星星的数量。接下里 nn 行,...原创 2018-01-22 16:49:57 · 822 阅读 · 0 评论 -
扩展欧几里得【模板】
扩展欧几里得:求形如ax+by=c方程的特解,并可以扩展出它的通解。ax+by=gcd(a,b);求通解只需要x/gcd(a,b)*c就可以了。模板:long long ex_gcd(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1; y=0;原创 2017-08-16 15:06:23 · 209 阅读 · 0 评论 -
快速幂【模板】
typedef long long LL;LL mod_pow(LL x, LL n, LL mod){ LL res = 1; while(n > 0) { if(n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res;}原创 2017-08-14 09:48:23 · 196 阅读 · 0 评论 -
LightOJ - 1259 Goldbach`s Conjecture【素数筛+枚举】
Goldbach`s ConjectureGoldbach'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 expre原创 2017-08-15 10:33:10 · 363 阅读 · 0 评论 -
LightOJ - 1234 Harmonic Number【调和级数求和】
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:In this problem, you are given n, you have to find Hn.InputInput starts with an integer T原创 2017-08-15 10:56:50 · 500 阅读 · 0 评论 -
LightOJ - 1370 Bi-shoe and Phi-shoe【欧拉函数的性质】
题目链接:https://cn.vjudge.net/problem/LightOJ-1370题意:给出n个数的欧拉值,求这n个数的和的最小值。欧拉函数:在数论,对正整数n,欧拉函数是小于n的正整数中与n互质的数的数目(φ(1)=1)。性质:欧拉函数是积性函数——若m,n互质, 特殊性质:当n为奇数时, , 证明与上述类似。若n为质原创 2017-08-15 14:56:20 · 251 阅读 · 0 评论 -
素数筛【模板】
埃氏筛法:存储n以内的所有素数int prime[MAX_N];bool is_prime[MAX_N+1];//返回n以内素数的个数int sieve(int n){ int p = 0; for(int i = 0; i<= n; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false...原创 2017-08-14 10:36:12 · 245 阅读 · 0 评论 -
LightOJ - 1282 Leading and Trailing
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.InputInput starts with an integer T (≤ 1000), denoting the num原创 2017-08-15 21:48:26 · 184 阅读 · 0 评论 -
51Nod - 1433 0和5
1433 0和5题目来源: CodeForces基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5。小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数。使得这个数尽可能大,而且可以被90整除。注意:1.这个数没有前导0,原创 2017-09-04 19:31:52 · 207 阅读 · 0 评论 -
POJ-2199 Rate of Return【二分求解一元高次方程】
Jill has been investing in a mutual fund for a while. Since her income has varied, the amount of money she has added to the investment has varied, and she hasn’t always added to the investment at regu原创 2017-10-18 20:32:19 · 753 阅读 · 0 评论 -
UVa-10375 Choose and divide 【唯一分解定理】
本题如果直接暴力相乘的话会超范围。这一题用到了唯一分解定理。概念:任意一个大于0的正整数都能被表示成若干个素数的乘积且表示方法是唯一的;整理可以将相同素数的合并;可以得到公式:n = P1^a1 * P2^a2 * …………* (P1 那么就可以先素数筛,然后用一个数组e存储第i个素数的指数。最后直接pow就可以了。这样就预先约掉了许多因子。代码:#includ原创 2017-12-08 21:27:33 · 268 阅读 · 0 评论 -
51Nod - 1019 逆序数【插入排序】
1019 逆序数基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。一个排列中逆序的总数就称为这个排列的逆序数。如2 4 3 1中,2 1,4 3,4 1,3 1是逆序,逆序数是4。给出一个整数序列,求该序列的逆序数。原创 2017-12-05 12:46:26 · 246 阅读 · 0 评论 -
Codeforces Round #461 (Div. 2) C. Cave Painting
Imp is watching a documentary about cave painting.Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a...原创 2018-02-08 22:49:09 · 128 阅读 · 0 评论 -
算法训练 最大最小公倍数
问题描述已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少。输入格式输入一个正整数N。输出格式输出一个整数,表示你找到的最小公倍数。样例输入9样例输出504数据规模与约定1 <= N <= 106。思路:1. 当n<3时,ans=n;2. 当n为奇数时,ans=n*(n-1)*(n-2);相邻的两个数互质。并且n与n-2相差2,且它们不是偶数,所以也互质。...原创 2018-02-12 22:10:30 · 209 阅读 · 0 评论 -
不可摸数【打表】
不可摸数Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15484 Accepted Submission(s): 4045Problem Descriptions(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)...原创 2018-03-29 19:40:28 · 400 阅读 · 0 评论 -
牛客小白月赛9 A 签到【逆元】
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述 你在一栋楼房下面,楼房一共有n层,第i层每秒有pi的概率会扔下一个东西并砸到你求第一秒内你被砸到的概率输入描述:第一行一个整数n之后有n行,第i+1行有两个整数ai,bi,表示输出描述:设答案为,你只需要找到一个...原创 2018-11-18 14:09:36 · 162 阅读 · 0 评论