Xdu 1022 (number theory screening), xdu1022
1022: A simple math problem 2 time limit: 1 Sec memory limit: 128 MB
Submitted: 73 solution: 13
[Submit] [Status] [discussion version] Question description Gaussian function: [x] indicates the largest integer less than or equal to x, that is, the rounded down. For example, [2.5] = 2, [1.2] = 1. Define function f (n) = [n/1] + [n/2] + [n/3] +... + [n/n]. sum (a, B) = f (a) + f (a + 1) +... + f (B) for a given a, B, sum (a, B) Input Multiple Input groups (up to 10000 groups) each line input a, B, where 1 <= a <= B <= 1000000 output multiple sets of output sum (a, B) % 1007 per row, and line feed sample input
1 11 2
Sample output
14
Prompt
Source
The meaning of f (n) is actually how many pairs (a, B) meet the requirements of a * B <= n (I did not expect it to be understood under the guidance of qijie, thank you ), then we can get g (n) to indicate how many pairs (a, B) Meet a * B = n, and then find a prefix for g and f (n.
#include<iostream>#include<algorithm>#include<cstdio>#include<vector>#include<cstring>#include<map>using namespace std;typedef long long ll;const int maxn = 1e6 + 10;const ll mod = 1007;#define rep(i,a,b) for(int i=(a);i<(b);i++)#define pb push_backll f[maxn];void init(int n){ memset(f,0,sizeof f); for(int i = 1; i <= n; i++) for(int j = i; j <= n; j += i) f[j]++; for(int j = 1; j <= n; j++) { f[j] = (f[j]+f[j-1])%mod; } for(int j = 1; j <= n; j++) { f[j] = (f[j]+f[j-1])%mod; }}int main(){ init(1000000); int L,R; while(~scanf("%d%d",&L,&R)) { printf("%d\n", (f[R]-f[L-1]+mod)%mod); } return 0;}