80 分求助
查看原帖
80 分求助
531930
Southern_Dynasty楼主2023/5/11 13:36

RT.

#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
#define int long long
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
const int N=1e4+5;
const int M=1e6+5;
const int mod=998244353;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline ll read(){
   	ll x=0;bool sgn=0;char ch=gt();
   	while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
   	while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
	return sgn?-x:x;
}
template<class T>
inline void print(T x){
	static char st[70];short top=0;
	if(x<0)pt('-');
    do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
    while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
	static char st[70];short top=0;
	if(x<0)pt('-');
    do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
    while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
	static char st[70];short top=0;
	if(x<0)pt('-');
    do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
    while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
	int siz=s.size();
	for(int i=0;i<siz;++i) pt(s[i]);
	printf("\n");
}
int T,tot;
ll n,sq,x[N],dp[N][N],pos1[M],pos2[M];
signed main(){
    T=read();
    while(T--){
    	n=read(),tot=0,sq=sqrt(n);
    	for(int i=1;i<=sq;++i){
    		if(n%i==0){
    			x[++tot]=i;
    			if(i!=sq) x[++tot]=n/i;
			}
		}
		sort(x+1,x+tot+1);
		for(int i=1;i<=(tot+1)/2;++i){
			pos1[x[i]]=i;
			pos2[x[i]]=tot-i+1;
		}
		for(int i=1;i<=tot;++i) for(int j=1;j<=tot;++j) dp[i][j]=0;
		for(int i=1;i<=tot;++i){
			dp[i][1]=(i==1);
			for(int j=2;j<=tot;++j){
				dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
				if(j>i) continue;
				if(x[i]%x[j]==0){
					ll tmp=x[i]/x[j];
					ll pos=(tmp<=sq)?(pos1[tmp]):(pos2[n/tmp]);
					dp[i][j]=(dp[i][j]+dp[pos][j-1])%mod;
				}
			}
		}
		println(dp[tot][tot]-1);
	}
	return 0;
}
2023/5/11 13:36
加载中...