链接:https://ac.nowcoder.com/acm/contest/5672/H
来源:牛客网
The following rules define a kind of integer tuple - the Legend Tuple:
(1, k) is always a Legend Tuple, where k is an integer.
if (n, k) is a Legend Tuple, (n + k, k) is also a Legend Tuple.
if (n, k) is a Legend Tuple, (nk, k) is also a Legend Tuple.
We want to know the number of the Legend Tuples (n, k) where 1 \le n \le N, 1 \le k \le K1≤n≤N,1≤k≤K.
In order to avoid calculations of huge integers, report the answer modulo 10^9+710
9
+7 instead.
输入描述:
The input contains two integers N and K, 1 \le N, K \le 10^{12}1≤N,K≤10
12
.
输出描述:
Output the answer modulo 10^9+710
9
+7.
示例1
输入
复制
3 3
输出
复制
8
示例2
输入
复制
3 9
输出
复制
14
题意:用题给的三种操作,问N , K范围内有多少个不同二元组 |
思路:
找找规律会发现对于每个k,n%k == 0的所有点都可以凑到,n%k == 1也如此。那么就每次累加(n/1 + n/2 + n/ 3…+ n/4…+n/k) + ((n-1)/1 + (n-1)/2 + (n-1)/ 3…+ (n-1)/4…+(n-1)/k) , 统计完去掉k=1时候重合的,加上除k>=2时候每次漏的1即是答案。利用整数分块算法解答。(最后累加完要多加个 + mod再取模,血的教训。。。)
AC代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(long long i=a;i<=n;++i)
#define per(i,n,a) for(long long i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi fir