#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> using namespace std; typedef long long LL; + ; //int prime[maxn + 1]; //第i个素数,保存区间内素数 bool is_prime[maxn]; //is_prime[i]为true表示i是素…
Problem Description The i’th Fibonacci number f(i) is recursively defined in the following way: •f(0) = 0 and f(1) = 1 •f(i + 2) = f(i + 1) + f(i) for every i ≥ 0 Your task is to compute some values of this sequence Input Input begins with an integer…
Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9745   Accepted: 5921 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
POJ3641 此题应归类为素数. POJ1995 http://poj.org/problem?id=1995 题意 求(A1^B1+A2^B2+ - +AH^BH)mod M. 思路 标准快速幂运算题目,算法复杂度为logN.不需要解释,直接看代码好了. 代码 Source Code Problem: 1995 User: liangrx06 Memory: 204K Time: 329MS Language: C++ Result: Accepted Source Code #includ…
Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5934   Accepted: 3461 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
第一道矩阵快速幂的题:模板题: #include<stack> #include<queue> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define INF 0x3f3f3f3f typedef long long ll; ; int n;…
给你一个数n,请问n以内有多少个素数?(n <= 10e7) 一般来说,要是对一个整数进行素数判断,首先想到的是写个函数判断是否为素数,然后调用这个函数,时间复杂度为O(n^(½)),但是要求n以内的素数就略显吃力了. 要是求n以内的素数个数的话,可以用埃式筛选.预处理一下. 先看下面的代码: /* |埃式筛法| |快速筛选素数| |15-7-26| */ #include <iostream> #include <cstdio> using namespace std; c…
题意: 求一个递推式(不好怎么概括..)的函数的值. 即 f(n)=a1f(n-1)+a2f(n-2)+...+adf(n-d); SOL: 根据矩阵乘法的定义我们可以很容易地构造出矩阵,每次乘法即可求出下一位f(n)的值并在距震中保存f(n)-----f(n-d+1). 像我这种傻逼看错好几次运算法则的人 = = 第一道矩乘对着老人家模板打得几乎一模一样-----只是觉得他的写法比较优雅= =(虽然我感觉那么多memcpy会不会让常数很大...) CODE: /*===============…
给出一个d阶线性递推关系,求f(n) mod m的值. , 求出An-dv0,该向量的最后一个元素就是所求. #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; typedef long long Matrix[maxn][maxn]; typedef long long Vector[maxn]; int d, n, m; void matrix_mul(Mat…
#include <cstring> #include <cstdio> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define LL long long LL p,res,a; bool judge_prime(LL k) { LL i; LL u=int(sqrt(k*1.0)); ;i<=u;i++) { ) ; }…