মঙ্গলবার, ২৬ মার্চ, ২০১৯

Harmonic number l8oj 1245

LIGHT OJ 1245


long long H( int n ) {
    
long long res = 0;
    
for( int i = 1; i <= n; i++ )
        res 
= res + n / i;
    
return res;
}

limit n=2^31;



///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%lld",&a)
#define sf2(a,b) scanf("%lld %lld",&a,&b)
#define sf3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
int main()
{
    long ts,cs=1;
    cin>>ts;
    while(ts--)
    {
        ll n,nn,i,ans,n1;
        cin>>n;
        nn=n;
        ans=n;
        n1=n;
        for(i=2;i<=nn;i++)
        {
            nn=n/i;
            ans=ans+(n1-nn)*(i-1);
            if(nn>(i-1))
            {
                ans+=nn;
            }
            n1=nn;
        }
        printf("Case %ld: %lld\n",cs++,ans);
    }
    return 0;
}
/*
How about the following idea. Say n = 36. So, the result is.
36/1 + 36/2 + 36/3 + ... + 36/36
Now,
36/1 = 36
36/2 = 18
from these two parts we are sure that
36/36 = 1
36/18 = 2
So, 36/19 = 36/20 = 36/21 = ... = 36/36 = 1
So, 36/19 + 36/20 + ... + 36/36 = 36 - 18 = 18.
Again,
36/2 = 18
36/3 = 12
from these two parts we are sure that
36/18 = 2
36/12 = 3
So, 36/13 = 36/14 = ... = 36/18 = 2
So, 36/13 + 36/14 + ... + 36/18 = (18 - 12)*2
*/

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factorization with prime Sieve

vector <int> prime; char sieve[1000009]; int N=1000009; void primeSieve ( ) { sieve[0] = sieve[1] = 1; prime.push_back(2); ...