E. Modular Stability

本文探讨了在给定正整数n和k的情况下,如何计算所有可能的稳定数组[a1,a2,...,ak]的数量,其中1≤a1<a2<⋯<ak≤n。稳定数组的定义是对于任意排列p和非负整数x,((x mod a1) mod a2)...mod ak-1) mod ak保持不变。文章提供了详细的算法实现和代码示例。

链接:https://codeforces.ml/contest/1359/problem/E

We define xmodyxmody as the remainder of division of xx by yy (%% operator in C++ or Java, mod operator in Pascal).

Let's call an array of positive integers [a1,a2,…,ak][a1,a2,…,ak] stable if for every permutation pp of integers from 11 to kk, and for every non-negative integer xx, the following condition is met:

(((xmoda1)moda2)…modak−1)modak=(((xmodap1)modap2)…modapk−1)modapk(((xmoda1)moda2)…modak−1)modak=(((xmodap1)modap2)…modapk−1)modapk

That is, for each non-negative integer xx, the value of (((xmoda1)moda2)…modak−1)modak(((xmoda1)moda2)…modak−1)modak does not change if we reorder the elements of the array aa.

For two given integers nn and kk, calculate the number of stable arrays [a1,a2,…,ak][a1,a2,…,ak] such that 1≤a1<a2<⋯<ak≤n1≤a1<a2<⋯<ak≤n.

Input

The only line contains two integers nn and kk (1≤n,k≤5⋅1051≤n,k≤5⋅105).

Output

Print one integer — the number of stable arrays [a1,a2,…,ak][a1,a2,…,ak] such that 1≤a1<a2<⋯<ak≤n1≤a1<a2<⋯<ak≤n. Since the answer may be large, print it modulo 998244353998244353.

Examples

input

Copy

7 3

output

Copy

16

input

Copy

3 7

output

Copy

0

input

Copy

1337 42

output

Copy

95147305

input

Copy

1 1

output

Copy

1

input

Copy

500000 1

output

Copy

500000

代码:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define maxn 200010
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define gep(i,x,y) for(int i=x;i>=y;i--)
ll n,T,m,h,k,t,x,y,max1,s,mod=998244353;
ll a[100001];
ll b[100001];
ll c[100001];
ll dp[100001];
const int N = 500000 + 5;
const int MOD = 998244353;
int F[N], Finv[N], inv[N];//F�ǽ׳ˣ�Finv����Ԫ�Ľ׳� 
void init(){
    inv[1] = 1;
    for(int i = 2; i < N; i ++){
        inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
    }
    F[0] = Finv[0] = 1;
    for(int i = 1; i < N; i ++){
        F[i] = F[i-1] * 1ll * i % MOD;
        Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD;
    }
}
int comb(int n, int m){
    if(m < 0 || m > n) return 0;
    return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;
}
int main()
{
	cin>>n>>k;
	if(k>n)
	{
		cout<<0<<endl;
	}
	else
	{
		init();
		for(int i=1;i<=n;i++)
		{
			t=floor(n*1.0/i);
			if(t>=k)
			{
				m=comb(t-1,k-1);
				s+=m;
				s%=mod;
			}
			else
			{
				break;
			}
		}
		cout<<s<<endl;
	}
}
	
		

 

<think>好的,我现在需要解决用户的问题:“Result type not match for select id="export" srcType: ... targetType: ...”。用户提到在导出时出现类型不匹配的错误,源类型是ActivePublicWelfareResponse,目标类型是ActivePublicWelfareExcel。这个问题通常出现在使用MyBatis进行数据库查询映射时,返回的结果类型与预期的目标类型不一致。让我一步一步分析可能的原因和解决方案。 首先,用户可能在MyBatis的Mapper XML文件中定义了一个select语句,其id为“export”,但resultType或resultMap指定的类型与代码中调用该方法时期望返回的类型不匹配。比如,可能Mapper中配置的是ActivePublicWelfareResponse,但调用导出功能时,希望得到ActivePublicWelfareExcel类型的对象列表,导致类型不兼容。 接下来,我需要检查Mapper XML中的对应select语句。假设用户使用的是resultType属性,可能错误地设置为srcType(com.guild.admin.modular.activePublicWelfare.model.response.ActivePublicWelfareResponse),而实际上应该使用targetType(ActivePublicWelfareExcel)。这会导致MyBatis尝试将查询结果映射到错误的类,从而引发类型不匹配异常。 另外,如果使用了resultMap,则需要确认resultMap是否正确指向了目标类型的映射配置。如果resultMap引用了错误的配置,同样会导致类型不匹配。此时需要检查resultMap的id是否正确,以及对应的字段映射是否与目标类ActivePublicWelfareExcel的属性一致。 还有一种可能性是,尽管resultType或resultMap配置正确,但ActivePublicWelfareResponse和ActivePublicWelfareExcel这两个类的结构不一致,比如字段名称、类型不匹配,导致MyBatis无法正确映射。这时候需要对比两个类的字段,确保数据库查询返回的列名与目标类的属性名能够对应起来,必要时可以使用MyBatis的别名功能或者显式的字段映射来调整。 此外,如果导出功能涉及到了数据转换,例如从Response对象转换为Excel对象,可能在Service层进行了手动转换,但查询时直接使用了Mapper返回的类型,而没有进行适当的转换处理。这种情况下,需要确保Mapper返回的类型与Service层所需的类型一致,或者在Service层进行类型转换。 可能的解决方案包括: 1. 修改Mapper XML中的resultType为正确的目标类型ActivePublicWelfareExcel。 2. 检查并修正resultMap的配置,确保其正确映射到目标类。 3. 调整查询语句中的字段别名,使其与目标类的属性名匹配。 4. 如果两个类结构差异较大,考虑使用中间转换层或工具(如MapStruct)进行对象转换。 用户还需要确认在调用MyBatis的select方法时,是否正确指定了结果类型。例如,在Java Mapper接口中,方法的返回类型应该是List<ActivePublicWelfareExcel>,而不是ActivePublicWelfareResponse。如果接口方法的返回类型错误,即使XML配置正确,也会导致类型不匹配。 另外,检查是否有多个同名的select语句或重复的id,导致MyBatis加载了错误的映射配置。确保每个select语句的id唯一,并且正确对应到目标结果类型。 最后,建议用户查看完整的错误堆栈信息,确定异常发生的具体位置,例如是在Mapper层映射时出错,还是在Service层进行类型转换时出错,这有助于更精准地定位问题。</think>出现 `Result type not match` 错误通常是因为 **MyBatis 的查询结果映射类型与代码中期望的类型不匹配**。根据你的描述,问题出在 `id="export"` 的查询语句中: - **源类型(srcType)**:`ActivePublicWelfareResponse` - **目标类型(targetType)**:`ActivePublicWelfareExcel` 以下是逐步排查和解决问题的方向: --- ### 1. 检查 Mapper XML 配置 在 MyBatis 的 `mapper.xml` 文件中,找到 `id="export"` 的 `<select>` 语句,确认其 `resultType` 或 `resultMap` 是否正确指向 **目标类型** `ActivePublicWelfareExcel`。 #### 错误示例(类型不匹配): ```xml <select id="export" resultType="com.guild.admin.modular.activePublicWelfare.model.response.ActivePublicWelfareResponse"> SELECT * FROM table </select> ``` #### 正确修复: ```xml <!-- 直接指定目标类型的全限定类名 --> <select id="export" resultType="com.guild.admin.modular.activePublicWelfare.domain.ActivePublicWelfareExcel"> SELECT field1, field2 FROM table </select> <!-- 或使用 resultMap(需提前定义映射关系) --> <select id="export" resultMap="activePublicWelfareExcelMap"> SELECT field1, field2 FROM table </select> ``` --- ### 2. 检查 `resultMap` 映射 如果使用 `resultMap`,确保其 `type` 属性指向 `ActivePublicWelfareExcel`,且字段映射正确: ```xml <resultMap id="activePublicWelfareExcelMap" type="com.guild.admin.modular.activePublicWelfare.domain.ActivePublicWelfareExcel"> <result property="excelField1" column="db_field1"/> <result property="excelField2" column="db_field2"/> </resultMap> ``` #### 关键点: - `property`:目标类(`ActivePublicWelfareExcel`)的字段名。 - `column`:数据库查询结果的列名。 --- ### 3. 检查 Java Mapper 接口 确认 Mapper 接口中方法的返回类型与 XML 中配置的 `resultType`/`resultMap` 一致: ```java // 正确:返回类型需与 XML 中定义的目标类型匹配 List<ActivePublicWelfareExcel> export(); // 错误:返回类型与 XML 配置的 resultType 不一致 List<ActivePublicWelfareResponse> export(); ``` --- ### 4. 验证字段映射 如果 `ActivePublicWelfareResponse` 和 `ActivePublicWelfareExcel` 的字段名或类型不一致,MyBatis 无法自动映射。 **解决方法:** - 在 SQL 查询中为字段添加别名,使其匹配目标类的字段名。 ```sql SELECT db_field1 AS excelField1, db_field2 AS excelField2 FROM table ``` - 使用 `resultMap` 显式定义映射关系(推荐)。 --- ### 5. 其他可能性 - **依赖冲突**:检查 MyBatis 版本是否稳定,避免因版本问题导致映射异常。 - **编译问题**:执行 `mvn clean install` 或 `Rebuild Project`,确保生成的类文件与代码一致。 --- ### 总结步骤 1. **修正 Mapper XML** 中的 `resultType` 或 `resultMap`,确保指向 `ActivePublicWelfareExcel`。 2. **检查 Java Mapper 接口** 的返回类型是否匹配。 3. **验证字段映射**,使用别名或 `resultMap` 解决字段名不一致问题。 4. 清理并重新编译项目,确保配置生效。 如果问题仍存在,建议提供 `ActivePublicWelfareResponse` 和 `ActivePublicWelfareExcel` 的类定义以及完整的 Mapper XML 配置,以便进一步分析。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值