
数论
追逐星辰的光
脚踏实地,虚心前行
展开
-
codeforces 338D GCD Table
Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.You have a sequence of positive integer num原创 2017-07-21 16:10:09 · 546 阅读 · 0 评论 -
数论-判断素数,输出素数,最短时间
判断一个数是不是素数:#include#includeint prime1(int x)//时间复杂度是O(√n){ if(x <= 1) return 0; double n = x+0.5; for(int i = 2; i <= sqrt(n); i++) if(x%i == 0) return 0; return 1;}int prime2(int x)//时间原创 2017-07-24 09:24:42 · 615 阅读 · 0 评论 -
快速幂优化
typedef long long ll;ll quick_mul(ll a, ll b, ll m) {//快速乘法运算 ll ans = 0; while(b) { if(b&1) ans = (ans + a) % m; a = (a + a) % m; b>>=1; } return ans;}ll quick_pow(ll a, ll b, ll m)原创 2017-10-25 20:06:11 · 244 阅读 · 0 评论 -
51node 1113
1113 矩阵快速幂基准时间限制:3 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 给出一个N * N的矩阵,其中的元素均为正整数。求这个矩阵的M次方。由于M次方的计算结果太大,只需要输出每个元素Mod (10^9 + 7)的结果。 Input第1行:2个数N和M,中间用空格分隔。N为矩阵的大小,M为M次方。(2 <= N <原创 2017-10-25 23:45:18 · 358 阅读 · 0 评论 -
莫比乌斯反演
typedef long long ll;const int MOD = 1e9+7;#define mod(x) (ll(x)%MOD)ll pow_m(ll a , ll n) { ll ret = 1; ll tmp = mod(a); while(n) { if(n&1) ret = mod(ret*tmp); tmp = mod(tmp*tmp); n >>原创 2017-10-26 20:51:08 · 237 阅读 · 0 评论 -
斐波那契额数列 矩阵快速
#include using namespace std;typedef long long ll;const int MOD = 1e9 + 7;#define mod(a) (ll(a)%MOD)struct MATRIX{ ll a[2][2];};MATRIX a;ll f[2];void ANS_Cf(MATRIX a) { f[0] = mod(a.a[0][0原创 2017-10-26 21:08:07 · 285 阅读 · 0 评论 -
大水题
链接:https://www.nowcoder.net/acm/contest/75/G来源:牛客网题目描述给出一个数n,求1到n中,有多少个数不是2 5 11 13的倍数。 输入描述:本题有多组输入每行一个数n,1输出描述:每行输出输出不是2 5 11 13的倍数的数共有多少。#include #define ll long longint原创 2018-02-04 21:11:42 · 258 阅读 · 0 评论 -
不凡的夫夫
链接:https://www.nowcoder.net/acm/contest/75/A来源:牛客网题目描述夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样,所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。输入描述:第一行是一个整数t(0<t<=1000000)(表示t组数据)接下来t行,每一行有一个整数n(0输出描述:输出n!在原创 2018-02-04 21:24:32 · 617 阅读 · 2 评论