【牛客多校 #7】 H Dividing 整数分块

本文介绍了如何利用整数分块算法解决牛客多校挑战赛中的Legend Tuple问题。通过对题目条件的分析,作者发现可以通过计算n%k的值来确定解决方案,并给出了避免大整数计算的技巧。文章提供了AC代码示例,详细解释了思路和计算过程。
摘要由CSDN通过智能技术生成

链接: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值