积性函数前n项和必看好文 https://blog.csdn.net/skywalkert/article/details/50500009 递归计算的时候要用map记忆化一下,前面的打表会比较快一点. AC代码 #include<bits/stdc++.h> using namespace std; ; typedef long long ll; map<ll,ll> ma; int check[maxn],prime[maxn],mu[maxn]; void Mobius(in
python基础——map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on Large Clusters”,你就能大概明白map/reduce的概念. 我们先看map.map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. 举例说明,比如我们有一个函数f(x)=
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2478 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 &l
求阶乘序列前N项和 #include <stdio.h> double fact(int n); int main() { int i, n; double item, sum; while (scanf("%d", &n) != EOF) { sum = 0; if (n <= 12) { for (i = 1; i <= n; i++) { item = fact(i); sum = sum + item; } } printf("%.0f
求平方根序列前N项和 #include <stdio.h> #include <math.h> int main() { int i, n; double item, sum; while (scanf("%d", &n) != EOF) { sum = 0; for (i = 1; i <= n; i++) { item = sqrt(i); sum = sum+item; } printf("sum = %.2f\n", s
求交错序列前N项和 #include <stdio.h> int main() { int numerator, denominator, flag, i, n; double item, sum; while (scanf("%d", &n) != EOF) { flag = 1; numerator = 1; denominator = 1; sum = 0; for (i = 1; i <= n; i++) { item = flag*1.0*numer
求简单交错序列前N项和 #include <stdio.h> int main() { int denominator, flag, i, n; double item, sum; while (scanf("%d", &n) != EOF) { flag = 1; denominator = 1; sum = 0; for (i = 1; i <= n; i++) { item = flag*1.0/denominator; sum = sum+item;
求奇数分之一序列前N项和 #include <stdio.h> int main() { int denominator, i, n; double item, sum; while (scanf("%d", &n) != EOF) { denominator = 1; sum = 0; for (i = 1; i <= n; i++) { item = 1.0/denominator; sum = sum+item; denominator = denomi
求N分之一序列前N项和 #include <stdio.h> int main() { int i, n; double item, sum; while (scanf("%d", &n) != EOF) { sum = 0; for (i = 1; i <= n; i++) { item = 1.0/i; sum = sum+item; } printf("sum = %f\n", sum); } return 0; }