Floor problem FZU - 2104

In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.

You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.


Input

The first line of the input contains an integer T (T≤100), indicating the number of test cases.

Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).

Output
For each test case, print the result of f(n,L)+f(n,L+1)+...+f(n,R) in a single line.
Sample Input
3
1 2 3
100 2 100
100 3 100
Sample Output
0
382
332

题意:输入n,L,R;

求所有floor(n/i)的和L<=i<=R;

思路:在cmath函数库 有floor函数,返回不大于x的最大整数

代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int T;
	cin>>T;
	while(T--){
		int n,l,r;
		cin>>n>>l>>r;
		int ans=0;
		for(int i=l;i<=r;i++)
		   ans+=floor(n/i);
		cout<<ans<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值