Page 1 of 1

12043 - Divisors

Posted: Wed Jul 06, 2011 9:26 pm
by shaon_cse_cu08
Hi...Some 1 please give me some critical Input for this problem.... I m getting WA again and again...please some 1 help me finding my bug :( :oops:

Code: Select all

#include<stdio.h>
#include<math.h>

void divisor(long a[],long n);
long d[100000];

int main()
{

    long t,a,b,k,i,cas=0,l;


    scanf("%ld",&t);

    while(++cas<=t)
    {
        scanf("%ld %ld %ld",&a,&b,&k);

        if(a==1&&b==1&&k==1)
        {
            printf("1 1\n");
            continue;
        }

        l=ceil(a/(float)k);

        i=0;

        while(l*k<=b)
        {
            d[i++]=l*k;
            l++;
        }

        divisor(d,i);

    }
return 0;
}

void divisor(long a[],long n)
{
    long i,j;
    long long sum_n=0,sum_d=0;

    for(i=0;i<n;i++)
    {
		for(j=2;j*j<a[i];j++)
		{
			if(!(a[i]%j))
			{
				sum_d+=j;

				sum_d+=a[i]/j;

				sum_n+=2;
			}
		}

		if(j*j==a[i])
		{
			sum_d+=a[i]/j;
			sum_n++;
		}

        sum_n+=2;
        sum_d+=(1+a[i]);

    }
    printf("%lld",sum_n);
    printf(" %lld\n",sum_d);

}

Re: 12043 Why WA!!!

Posted: Tue Jul 12, 2011 9:26 pm
by Eather
Shaon, Please check this input:
1
1 100000 1

Correct answer is: 1166750 8224740835

But, yours code give the output: 1166751 8224740836

Check the calculation.

wish you good luck

Re: 12043 Why WA!!!

Posted: Tue Jul 12, 2011 9:28 pm
by Eather
shaon_cse_cu08 wrote:Hi...Some 1 please give me some critical Input for this problem.... I m getting WA again and again...please some 1 help me finding my bug :( :oops:
Please check this input:
1
1 100000 1

Correct answer is: 1166750 8224740835

But, yours code give the output: 1166751 8224740836

Check the calculation.

wish you good luck

Re: 12043 pls help where is the problem?? can anyone find it

Posted: Sat Jan 25, 2014 10:53 pm
by cse dipto

Code: Select all

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#define size 1000000

using namespace std;

long long int a1[size],b1[size],c[size];

int main()
{
    long long int i,j,k,l,t,a,b,d,index=0,max,count,num,nr,index2,temp;
    double sum,temp2,r,r1,sr;
    max=100000;
    b1[index++]=2;
    for(i=3;i*i<=max;i+=2)
    {
        if(a1[i]==0)
        {
            b1[index++]=i;
            for(j=i*3;j<=max;j+=i*2)
            {
                a1[j]=1;
            }
        }
    }
    cin>>t;
    for(i=1;i<=t;i++)
    {
        cin>>a>>b>>d;
        index2=0;
        for(j=a;j<=b;j++)
        {
            if(j%d==0)
            {
                c[index2++]=j;
            }
        }
        nr=0;
        sr=0;
        for(k=0;k<index2;k++)
        {
            temp=c[k];
            num=1;
            sum=1;
            for(l=0;l<index;l++)
            {
                count=0;
                while(temp%b1[l]==0)
                {
                    temp=temp/b1[l];
                    count++;
                }
                temp2=b1[l];
                r=pow(b1[l],(count+1));
                r1=((r-1)/(b1[l]-1));
                sum=(sum*r1);
                num=(num*(count+1));
            }
            nr=nr+num;
            sr=sr+sum;
        }
        printf("%lld %0.0lf\n",nr,sr);
    }
    return 0;
}

Re: 12043 Why WA!!!

Posted: Mon Jan 27, 2014 10:56 pm
by brianfry713
Try solving it without using floating point.

12043 - Divisors

Posted: Sat Feb 28, 2015 5:20 am
by RookiE3
I don't understand why am I getting WA in this problem

Code: Select all

#include <stdio.h>

long long num, sum;

int d(int n)
{
    int i;
    sum = 0;
    num = 0;
    for(i=1; i*i<n; i++)
    {
        if(n % i == 0)
        {
            num += 2;
            sum += i + n/i;
        }
    }
    if(i*i == n)
    {
        num += 1;
        sum += i;
    }
}

int main()
{
    int a, b, k;
    long long g, h;
    int i, t, n;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d %d %d", &a, &b, &k);
        g = 0;
        h = 0;
        if(a == b)
        {
            if(a%k == 0)
            {
                d(a);
                printf("%lld %lld\n", num, sum);
            }
            else
                printf("0 0\n");
            continue;
        }
        if(a % k == 0)
            i = a / k;
        else
            i = (a/k+1) * k;
        for(; i<=b; i+=k)
        {
            d(i);
            g += num;
            h += sum;
        }
        printf("%lld %lld\n", g, h);
    }
    return 0;
}
Please help

Re: 12043 - Divisors

Posted: Fri May 22, 2015 3:34 pm
by coder.tanvir
Check the case
input

Code: Select all

1
3 6 3
output

Code: Select all

6 16