FZU 2104 Floor problem (水题)
Problem 2104 Floor problem
Accept: 546 Submit: 615
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
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
Source
“高教社杯”第三届福建省大学生程序设计竞赛
注意int本来是向下取整即可
1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 #include<stdlib.h> 5 #include<algorithm> 6 using namespace std; 7 int main() 8 { 9 //freopen("in.txt","r",stdin); 10 int kase; 11 scanf("%d",&kase); 12 while(kase--) 13 { 14 int n,l,r; 15 int sum=0; 16 scanf("%d %d %d",&n,&l,&r); 17 for(int i=l;i<=r;i++) 18 sum+=n/i; 19 printf("%d\n",sum); 20 } 21 return 0; 22 }