12043 - Divisors

All about problems in Volume 120. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

12043 - Divisors

Post by shaon_cse_cu08 » Wed Jul 06, 2011 9:26 pm

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);

}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

Re: 12043 Why WA!!!

Post by Eather » Tue Jul 12, 2011 9:26 pm

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

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

Re: 12043 Why WA!!!

Post by Eather » Tue Jul 12, 2011 9:28 pm

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

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

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

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

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12043 Why WA!!!

Post by brianfry713 » Mon Jan 27, 2014 10:56 pm

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!

RookiE3
New poster
Posts: 16
Joined: Tue Feb 18, 2014 7:59 pm

12043 - Divisors

Post by RookiE3 » Sat Feb 28, 2015 5:20 am

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

coder.tanvir
New poster
Posts: 11
Joined: Mon Mar 09, 2015 10:30 am

Re: 12043 - Divisors

Post by coder.tanvir » Fri May 22, 2015 3:34 pm

Check the case
input

Code: Select all

1
3 6 3
output

Code: Select all

6 16

Post Reply

Return to “Volume 120 (12000-12099)”