বুধবার, ১৩ এপ্রিল, ২০১৬

LightOJ 1098 - A New Function

Today we will discuss about a problem of LightOJ 1098 - A New Function:

At first the basic concept which will need  that is for :

(A number d appears \lfloor N/d\rfloor times as a divisor of the numbers 1\ldots N. (Try it on paper if you don't see this) Because the number itself should not be counted, we have to substract 1 from this. This leads to this algorithm: \sum _{{2\leq d\leq N}}d(\lfloor {\frac  {N}{d}}\rfloor -1). This formula gives the right results, but is way to slow.  )

Let P =  1 - 25

let for 25 there is (25/2)-1 times two's in her and for 25 there are (25/3)-1 times

3's and like this,(25/4)-1 times 4's and (25/5)-1 times 5's,(25/6)-1 times 6's........

...(25/12)-1 times 12 and then it is not possible  to go further.

now here comes the main process ,that is calculation...

here we make a list for 25:

There are 2: 11 times;

3: 7 times;

4:5 times;

5:4 times;

8: 2 times;

9=1 times;

10=1 times;

11:1 time;

....

12:1 times;

now we will calculate the sum for 1 to 12;

that is let i=12, the p=(i*(i+1))/2-(1*2))/2(as,upto 1 was not present); still there remains (11-1) two's;

q=2*10;

then,we will calculate like this for   3 to 8;

then for  4 to 6 and at last 5 to 5;

by this we will get the result.

 #include <bits/stdc++.h>
#include <math.h>
#define ll long long int
#define Max 1000
using namespace std;
ll y;
ll recursion(ll sum,ll a,ll k)
{  ll p,q;

    p=(k*(k+1))/2-(((a-1)*a)/2);
    q=a*(k-a);
   if(q>=0) sum=sum+(p+q);
    if(q<=0) return sum;
   else {
       a++;
   k=y/a;
   if(a>k) return sum;
        recursion(sum,a,k);
   }



}
int main(){
ll tc,cnt=1;
cin>>tc;
while(tc--){
    ll a,x,sum=0;
   scanf("%lld",&y);
    x=recursion(0,2,y/2);
   printf("Case %lld: %lld\n",cnt++,x);


}
}

you can also check: http://rizoantoufiq.blogspot.com/2015/12/lightoj-1098-new-function.html

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

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