## 12043 - Divisors

Moderator: Board moderators

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

### 12043 - Divisors

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

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 .....

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

### Re: 12043 Why WA!!!

1
1 100000 1

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!!!

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
1
1 100000 1

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

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!!!

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

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

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

### Re: 12043 - Divisors

Check the case
input

Code: Select all

``````1
3 6 3
``````
output

Code: Select all

``````6 16
``````