Time Complexity of O (N*log (N))
Time Complexity Accurate procedure:
n * (1 + 1/3 + + +) + 1/n) ~ ~ N*inn
So the time complexity of the second for loop is about O (N*log (N))
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath > #include <map> #include <set> #include <list> #include <cassert> #include <string># Include <climits> #include <algorithm>using namespace std; #define MAXN 5000000#define Left (i) (2*i+1) # Define Right (i) (2*i+2) #define _CP (A, B) ((a) < (b)) #define MIN (A, B) ((a) < (b)? ( A):(B)) #define MAX (A, B) ((a) > (b)? ( A):(B)) #define RST (n) memset (n, 0, sizeof (n)) int sum[maxn+10]; Prevent overflow int main () {freopen ("Data.out", "w", stdout); for (int i=0; i<=maxn; i++) sum[i]=1; 1 is the true factor of all numbers, so all 1//preprocessing, Time complexity O (N*log (N)) for (int i=2; i+i<=maxn; i++) {//5 million The true factor less than half in T J = i + i; Because it is a true factor, it cannot be added itself while (J <= Maxn) {Sum[j] + = i; All the multiples of I plus i j + = i; }} for (int i=220; i<=maxn; i++)//scan {//Go to weight, determine if cross-border, judge Affinity if (Sum[i]>i && SUM[I]<=MAXN & Amp;& sum[sum[i]]==i) {printf ("%d%d\n", I, sum[i]); }} return 0;}
Copyright notice: I feel like I'm doing a good job. I hope you can move your mouse and keyboard for me to order a praise or give me a comment, under the Grateful!_____________________________________________________ __ Welcome reprint, in the hope that you reprint at the same time, add the original address, thank you with
Affinity number within 5 million