数论
欧莎
啦啦啦,啦啦啦,让我们一起洗刷刷
展开
-
随机采样算法(从N个数中抽取M个数) C++
#include <iostream>#include <algorithm>#include <iterator>#include <vector>//假设这n个数的序号依次为0,1,2,...,n-1,数组名为numvoid knuth1(std::vector<int> pNum, int m, int n){ srand((unsigned int)time(0)); for (int i = 0; i < n; i.原创 2020-08-13 18:00:07 · 3516 阅读 · 0 评论 -
线性筛选求素数
几种方法求素数的1 目前是我见过的较快的速度求素数了#include#include#includechar whe[1000001];int main(){ clock_t t1,t2; int t,count=0; t1=clock(); for(int i=2; i<=1000; i++) if(whe[i]==0)原创 2016-12-10 21:43:51 · 291 阅读 · 0 评论 -
FZU oj 1759 Super A^B mod C (快速幂+指数循环节+欧拉函数)
Problem DescriptionGiven A,B,C, You should quickly calculate the result of A^B mod C. (1 InputThere are multiply testcases. Each testcase, there is one line contains three integers A, B and原创 2017-02-22 20:27:09 · 384 阅读 · 0 评论 -
hud 1030 Delta-wave(数论)
A triangle field is numbered with successive integers in the way shown on the picture below.The traveller needs to go from the cell with number M to the cell with number N. The traveller原创 2017-03-12 14:09:57 · 183 阅读 · 0 评论 -
hud 5750 Dertouzos (数论+暴力)
Problem DescriptionA positive proper divisor is a positive divisor of a numbern, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.Peter h原创 2017-03-22 20:45:40 · 309 阅读 · 0 评论 -
hdu 5317 RGCDQ
Problem DescriptionMr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RG原创 2017-03-15 16:01:24 · 154 阅读 · 0 评论 -
hdu 1250 Hat's Fibonacci(高精度)
Problem DescriptionA Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n -原创 2017-03-17 10:28:48 · 145 阅读 · 0 评论 -
费马小定理判断素数
// 根据费马小定理判断P是否为一个素数#include <iostream>#include<stdio.h>#include<algorithm>using namespace std;typedef long long ll;ll p;ll Pow(ll a,ll b){ ll res=1; while(b) { if(b&1) res=原创 2017-04-06 15:41:08 · 1972 阅读 · 0 评论 -
扩展欧几里得 (求两个数的最大公约数)
#include <algorithm>#include <string.h>#include <iostream>#include <stdio.h>#include <string>#include <vector>#include <queue>#include <map&原创 2018-03-27 18:11:20 · 488 阅读 · 0 评论 -
ZZULIOJ (郑轻) 1898(找规律)
Description985有n个数,已知每次操作可以将其中不相同的两个数一个加一、一个减一,操作次数不限。 问他最多可以得到多少个相同的数。 Input第一行输入一个整数t,代表有t组测试数据。 每组数据占两行,第一行输入一个n代表元素个数,下面一行输入n个整数a[]。 注:1 <= t <= 30,1 <= n <= 1e4,1 <= a[] <= 1e3。 Output输出一个整数代原创 2016-08-04 18:27:14 · 427 阅读 · 0 评论 -
产生随机数
#include#includeusing namespace std;int main(){ freopen("in.txt","w",stdout); srand(time(NULL)); int t; t=rand()%100+1; printf("%d\n",t); for(int k=0; k<t; k++) {原创 2016-10-07 14:51:49 · 254 阅读 · 0 评论 -
产生随机的字符串
#include#include#include#includeusing namespace std;int len;//产生长度为length的随机字符串char* genRandomString(int length){ int flag, i; char* string; srand((unsigned) time(NULL )); if (原创 2016-10-26 20:34:38 · 337 阅读 · 0 评论 -
nyist 737 石子合并(一)
描述 有N堆石子排成一排,每堆石子有一定的数量。现要将N堆石子并成为一堆。合并的过程只能每次将相邻的两堆石子堆成一堆,每次合并花费的代价为这两堆石子的和,经过N-1次合并后成为一堆。求出总的代价最小值。 输入 有多组测试数据,输入到文件结束。 每组测试数据第一行有一个整数n,表示有n堆石子。 接下来的一行有n(0< n <200)个数,分别表示这n堆石子的数目,用空格隔开 输出原创 2016-07-23 08:29:23 · 263 阅读 · 0 评论 -
hdu 5734 Acperience 2016 Multi-University Training Contest 2
Problem Description Deep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular typ原创 2016-07-22 10:02:39 · 214 阅读 · 0 评论 -
nyist 769 乘数密码(扩展欧几里得求逆元)
描述乘数密码也是一种替换密码,其加密变换是将明文字母串逐位乘以密钥k并进行模运算,数学表达式如下:E(m)=k*m mod q, gcd(k,q)=1 (即k,q互素)。当k与q互素时,明文字母加密成密文字母的关系为一一映射。现有一经过乘法加密的密文,请破译出它的明文。输入输入包含多组数据,不超过1000组。每组包含一个字符串和一个正整数原创 2016-09-22 20:51:54 · 420 阅读 · 0 评论 -
欧拉函数(数论)
欧拉函数的定义:对正整数n,欧拉函数是小于等于n的数中与n互质的数的数目。 我们令f(n)为欧拉函数 (1).其中当n=1时,f(1)=1,没有任何实质的意义。 (2).特别的如果两个素数p和q,且n=pq,则f(n)=(p-1)(q-1); (3).若n是质数p的k次幂,f(n)=p^k-p^(k-1)=(p-1)p^(k-1),因为除了p的倍数外,其他数都跟n互质。 (4).原创 2016-09-21 21:56:12 · 840 阅读 · 0 评论 -
求解一次同余式和中国剩余定理的模板
我的专业是信息对抗所以我们就学习了一些信安数学基础,我也是蛮喜欢的,所以就写写求解一次同余式的代码一次同余式的定义: 一次同余方程ax≡b(mod)m有解的充分必要条件是(a,m)|b,且当其有解时,其解数为(a,m)。求解一次同余式#include<stdio.h>#include<bits/stdc++.h>using namespace std;int x,y,q;int gcd(i原创 2016-11-03 21:46:38 · 1888 阅读 · 0 评论 -
快速幂的模板 (数论)
#includeusing namespace std;long long quickmod(long long a,long long b,long long m){ long long ans = 1; while(b)//用一个循环从右到左便利b的所有二进制位 { if(b&1)//判断此时b[i]的二进制位是否为1 {原创 2016-09-27 19:48:43 · 301 阅读 · 0 评论 -
费马素数 (Fermat)
在int 范围内费马素数共有15个#includeusing namespace std;int prime[100];int mi(int n){ int ans=1; for(int i=1;i<=n;i++) { ans*=4; } return ans;}int main(){ int n; whil原创 2016-10-16 17:07:08 · 1190 阅读 · 0 评论 -
梅森素数(Mersenne)
//梅森素数#includeusing namespace std;int mi(int n){ int ans=1; for(int i=1;i<=n;i++) { ans*=2; } return ans;}int main(){ int p;//输入的P是一个素数 while(~scanf("%d",&p)原创 2016-10-16 17:32:40 · 1246 阅读 · 0 评论 -
Ancient Berland Circus
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon,转载 2016-05-02 21:08:29 · 436 阅读 · 0 评论