TOJ 2861. Divisors

妙题,与坐标系结合起来,曲线x*y=n上以及以下的整数坐标点总个数为小于等于n的数的约数总数,然后用x=y这条直线分成两部分,重复的部分减去。

We define the function f(x) = the number of divisors of x. Given two integers a and b (ab), please calculate f(a) + f(a+1) + ... + f(b).

Input

Two integers a and b for each test case, 1 ≤ ab ≤ 2 31 - 1. The input is terminated by a line with a = b = 0.

Output

The value of f(a) + f(a+1) + ... + f(b).

Sample Input

9 12
1 2147483647
0 0

Sample Output

15

46475828386

#include<iostream>
#include<cmath>
using namespace std;
long long f(long long a){
	long long count=0,i;
	for(i=1;i*i<=a;i++){
		count=count+a/i-i+1;
	}
	return count*2-(int)sqrt(a);	
}
int main(){
	long long a,b,r;
	while(cin>>a>>b&&a&&b){
	//	r=0;
		//for(int i=a;i<=b;i++)
		//	r=r+f(i);
		cout<<f(b)-f(a-1)<<endl;

		//cout<<f(a)<<endl;
		//cout<<f(b)<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值