# [qbxt考试Day6]小学数学 + Hash

### T1

n <= 10^16

1、因子个数与质因子大小无关
2、设X = P1^a1 * P2^a2 * P3^a3，因子数 = (a1 + 1) * (a2 + 1) *(a3 + 1)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define INF 1e9 + 7
#define LL long long
using namespace std;
const int MAXN = 1000 + 5;
LL n;
LL cnt[MAXN];
LL prime[] = {0,2,3,5,7,11,13,17,19,23,29,31};
LL num,ans;
void dfs(LL gs,LL sum,LL k)
{
if(k > 12)return;
if(gs > num || (gs == num && sum < ans))
num = gs,ans = sum;
cnt[k] = 0;
while(sum * prime[k] <= n && cnt[k] + 1 <= cnt[k - 1])
{
cnt[k] ++;
sum *= prime[k];
dfs(gs * (cnt[k] + 1),sum,k + 1);
}
}
int main()
{
freopen("divisors.in","r",stdin);
freopen("divisors.out","w",stdout);
scanf("%lld",&n);
cnt[0] = INF;
dfs(1,1,1);
printf("%lld",ans);
fclose(stdin);
fclose(stdout);
return 0;
}

### T2

e.
In
9
1 2 2 1 5 5 7 7

Out
1 2 3 3 4 3 2 3 3

hash每一颗子树

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int MAXN = 100000 + 50;
struct edge
{
int f,t;
}l[MAXN << 1];
void init(int n)
{
for(int i = 1;i <= n;i ++)
}
void build(int f,int t)
{
l[++ tot] = (edge){f,t};
}
int x;

map <vector<int>,int> id;
int cnt,num[MAXN];
int dfs(int u)
{
vector <int> p;
p.clear();
for(int i = head[u];i != -1;i = next[i])
{
int t = l[i].t;
p.push_back(dfs(t));
}
sort(p.begin(),p.end());//vector是有序的
if(!id[p])id[p] = ++ cnt;
return num[u] = id[p];
}
int tmp,ans[MAXN];
bool vis[MAXN];
int main()
{
freopen("tree.in","r",stdin);
freopen("tree.out","w",stdout);
scanf("%d",&n);
init(n);
for(int i = 1;i <= n - 1;i ++)
{
scanf("%d",&x);
build(x,i + 1);
}
dfs(1);
for(int i = 1;i <= n;i ++)
{
if(!vis[num[i]])
{
ans[num[i]] = ++ tmp;
vis[num[i]] = true;
}
}
for(int i = 1;i <= n;i ++)
{
printf("%d ",ans[num[i]]);
}
fclose(stdin);
fclose(stdout);
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：[qbxt考试Day6]小学数学 + Hash 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)