D16 T2 summer boredom (deep search)

The meaning of problems

Seeking [1, n] has a count interval of up to about divisor, divisor number and outputs its count to about her, such as about 12 1,2,3,4,6,12 number, these numbers have 1,2,2,3,4,6 about a number, then the number of about 12 to about 18 numbers there.

To 100% of the data, n <= 1e18

answer

Violence is quite miss

const int maxn=2000005;
ll n;
ll num[maxn],sum[maxn];//约数个数,约数的约数和 
ll ans;

int main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        num[i]++;
        sum[i]+=num[i];
        if(sum[i]>sum[ans]) ans=i;
        for(ll j=2*i;j<=n;j+=i){
            num[j]++;
            sum[j]+=num[i];
        }
    }
    //for(int i=1;i<=n;i++) printf("%d ",sum[i]);
    printf("%d\n%d",ans,sum[ans]);
}
View Code

Had wanted to find something to play table, the answer will be under the jurisdiction of a range, within range of 1e7 was less than 70, and some interval length is up to about counting the number of covenant, had wanted to start from, but not a single length increase , on the GG.

Something positive solution is the number theory.

For a number n, it can be decomposed into P . 1 R1 P 2 R2 ... P m RM , his number is about the number (r1 + 1) (r2 + 1) .... (rm + 1) th;

Can be found from the above, only about a few number of index-related, so simultaneously, R & lt divisor number in phase I > = R & lt I +. 1 will be better;

The divisor of n and a distributive law of multiplication of (P1 + P1. 1 + 2 + ... P1 R1 ) (P2 + P2. 1 + 2 + ... P2 R2 ) ... (PM + PM +. 1 2 +. ..pm RM ), then over the number of analog it is about the number of divisors (1 + 2 + .. + ( r1 + 1)) (1 + 2 + ... + (r2 + 1)) ... ( 1 + 2 + ... + (rm + 1)), one can imagine a number in each parenthesis selected, it will be a way to match the index divisor, which left most of the corresponding borrowing from the number obtained about the number is the same.

This can be found only with the related index, the R & lt I > = R & lt I +. 1 will be better

And the number of primes is divided into different 1e18 up to 53, it can be a burst search

#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll n;
int prime[20]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
ll ans1,ans2;

void dfs(int pos,ll ret,ll num,intlast) {
     if (right> n) return ;
    if (num> ans2) { 
        ans2 = num; 
        ANS1 = right; 
    } 
    Else  if (num == ans2) 
     ANS1 = my (ANS1, right);
    for ( int i = 1 ; i <= last right && <= N / prime [pos]; i ++ ) { 
        right * = prime [pos]; 
        DFS (pos + 1 , right, num * ((i + 1 ) * (i + 2 )) / 2 , i); 
    } 
} 

Int main(){
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
    scanf("%lld",&n);
    dfs(1,1,1,60);
    printf("%lld\n%lld",ans1,ans2);
}
View Code

 

Guess you like

Origin www.cnblogs.com/sto324/p/11266192.html
D16