Solution: Number of research about

This is the first time to write this konjac solution to a problem, so excited.

Here are my four ** ** There are two kinds of solution _ ~ ~ ~ ~ _ magical compare

 

------------

# method one

Starting right about positive solutions, other explanations are explained in detail, I will not detail. Focus is on the following three methods.
CPP `` `
#include <the iostream>
the using namespace STD;
typedef Long Long LL;

ll n, ans;

main int () {
CIN n->>;
for (int I =. 1; I <= n-; I ++) {
ANS = n-+ / I;
}
COUT ANS << << endl;
return 0;
}
`` `
Time Complexity degree: O (n) ~~ ~~ should

~ ~ ~ ~ Streamline extremely simple, is not it?

 

------------

Method # 2

However, the konjac test when the ventilation did not expect.

This question solution to a problem I see there are many huge guys have put a variety of methods to spend, but I want to introduce a method, was thought of when I test simulation game. That's
# ~ ~ ~ ~ _ _ play table

Yes, you heard it right. I was to do with the violence only water for 70 minutes, then I think our guys a huge room playing table A of emirp, thinking, simply to wave play table feeling it ~ ~ ~ ~ really fun to play table .

Ideas: time complexity of violence is O (n * $ \ sqrt {n} $) ~~ make a root played five minutes to play out, for the first time since data written explanations ~ 10 ^ 6 will be fried. ~ 10 ^ 5 per let us fight a number of tables, then solve the violence factor intervals of less than 10 ^ 5. ~~

_ ~~ exam when I was a teacher looked my way, and then the teacher put his mouth spit out tea, said: ~~ _

# You tumor ah!

Playing table generator:

```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

#define maxa 1000001
#define int long long
using namespace std;

int ans,n;
int zhi[maxa],vis[maxa];
void y(int x){
int k=sqrt(x);
for(int i=1;i<=k;i++){
if(x%i==0)ans+=2;
}
if(x==k*k)ans--;
}
void fp(){
for(int i=1;i<=n;i++){
y(i);
}
}

main () {
cin >> n;
fp ();
cout << years;
}
`` `

 

AC Code:

```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

#define maxa 1000001
#define int long long
using namespace std;

int ans,n,m;
int zhi[maxa],vis[maxa];
int ans1[]={1166750,2472113,3829833,5221472,6638449,8075504,9529316,10997454,12478206,13970034};//传说中的打表
void y(int x){
int k=sqrt(x);
for(int i=1;i<=k;i++){
if(x%i==0)ans+=2;
}
if(x==k*k)ans--;
}
void fp(){
for(int i=m;i<=n;i++){
y(i);
}
}

main () {
CIN >> n-;
IF (n-> = 100000) {
ANS + = ANS1 [(n-/ 100000) -1];
}
m = n-/ 100000;
m * = 100000;
m ++;
FP ();
COUT < <ANS;
}
`` `
time complexity: O (n / 10 ~~ metaphysical 10 ~~ * $ \ sqrt {n / 10} $)

But note that if your machine is not good evaluation ~ ~ ~ ~ Ji, there may be a point T. (999,998)

------------

# Method three

In fact, at the time when the examination is similar to the idea I had prime number sieve to do, but I have a WA. I later revised it. Each number is probably enumerate, if there is a multiple of it, then ans + = 2. The square of the number of special sentenced to click on it.

Code:

```cpp
#include <iostream>
#include <cstdio>
using namespace std;
int n,primes[1000005],pc=0,vis[1000005],cnt[1000005],ans;
int main() {
cin>>n;
for(int i=1;i<=n;i++) cnt[i]=1;
//素数筛
for(int i=2;i<=n;i++) if(cnt[i]<=1) {
primes[pc++]=i;
for(int j=1;j*i<=n;j++) {
vis[i*j]++;
int tmp=j,c=2;
while(tmp%i==0) tmp/=i,c++;
cnt[i*j]*=c;
}
}
for(int i=1;i<=n;i++) ans+=cnt[i];
cout<<ans;
}
```
时间复杂度:O(nlogn).

 

------------

# Method Four

This method is absolutely unprecedented, and no to significant. Because this code is the room where our national team undercover. He did the legendary
# n party than a million mark grind violence counted!
And our teachers retest several times, his code run fast, 4 ~ 5ms, up to 59ms.
He just avoid all the data.
## He is the
# cpy big giant guy

Code:
(because he was too huge, so I am afraid this part of the code scared Luo Gu omitted here.)

`` `
#Include <bits / STDC ++ H.>
The using namespace STD;
int n-;
Long Long ANS [1000005], ANSS =. 1, J =. 1;
int main () {
ANSS =. 1;
CIN n->>;
for ( . 1 I = int; I <= n-; I ++) ANS [I] =. 1;
for (int I = 2; I <= n-; I ++) {
// here mosaic effect, because he is too huge a!
. 1 = J;
}
for (int I = 2; I <= n-; I ++) {
ANSS ANS = + [I];
}
COUT << ANSS;
}
`` `

Time complexity: O (n ^ 2)
was found, the algorithm and the actual speed comparable method.

 

------------
Those are the adorable new solution to a problem, this is my first problem solutions, has written more than two hours. God also hope you ran a lot of tolerance.

 

Guess you like

Origin www.cnblogs.com/WQT-FFT/p/11266570.html