Solution to a problem P1403 [[AHOI2005] about the number of research]

topic

Many people see the explanations given directly region Conclusion: The answer is \ (\ DisplayStyle \ sum_. 1} ^ {n-I = \ {n-lfloor \ I} over \ rfloor \) , proof is not given, here demonstrated


【analysis】

First, we can know \ (\ displaystyle f (n) = \ sum_ {d \ mid n} 1 \)

Some students do not understand this formula, I explain this formula expression:

Enumeration \ (n-\) factor \ (D \) , each enumerator factor \ (D \) , \ (F (n-) \) plus \ (1 \)

\ (d \ mid n \) means \ (D \) is \ (n-\) factor

: In this way, we can correspond to the subject and the \ (f (n) \) Representative \ (n-\) number factor


\ (\ displaystyle f (n) = \ sum_ {d \ mid n} 1 \) there is an expression \ (\ displaystyle f (n) = \ sum_ {d = 1} ^ n [d \ mid n] \)

Behind the heck \ ([d \ mid n] \) is a function of true or false, is correct \ (1 \) , the error is \ (0 \)

This should be understood that it is not difficult:

Enumerate every number \ (D \) , when the \ (D \) is \ (n-\) when factor, \ (F (n-) \) plus \ (1 \)


Requirements of the subject \ (\ displaystyle M = \ sum_ {i = 1} ^ nf (i) \)

We into the above definition equation:

\(\quad \displaystyle M\)

\(\displaystyle=\sum_{i=1}^n\sum_{d\mid i}1\)

\(\displaystyle=\sum_{i=1}^n\sum_{d=1}^i[d\mid i]\)

We exchange about the order of enumeration, the \ (d \) enumeration in advance.

Considered equivalent \ (d = 1 \) , the on \ (i = 1,2,3 \ dots n \) contribution; \ (D = 2 \) when \ (i = 1,2,3 \ dots n-\) contribution; \ (\ DOTS \) ; \ (n-D = \) when \ (i = 1,2,3 \ dots n \) contribution

\(\displaystyle=\sum_{d=1}^n\sum_{i=1}^n[d\mid i]\)

For a fixed \ (D \) , \ (\ DisplayStyle \ sum_. 1} ^ {I = [D \ MID I] n-\) a very intuitive meaning:

\ (. 1 \) ~ \ (\ n-) , of the number to the number of \ (D \) is a factor, i.e. the number is much \ (D \) multiple

It should be \ (\ lfloor {n \ over d} \ rfloor \) bar

So we get \ (\ displaystyle M = \ sum_ {d = 1} ^ n \ lfloor {n \ over d} \ rfloor \)


[Code]

That would put this konjac My code is very ugly wind Code:

C ++ version:

#include<iostream>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) ans+=n/i;
    cout<<ans;
}

Python version 3:

ans=0
n=int(input())
for i in range(1,n+1):
    ans+=n//i
print(ans)

Finally Amway about this Tacca's blog

Guess you like

Origin www.cnblogs.com/JustinRochester/p/12290695.html