Day 4
T1
上来思路就是暴力找出来每个数的只因数及其个数,然后暴力累乘
但是不对
只需要记每个数最多含多少个即可
做完就行
赛时写完了觉得自己很稳
结果挂分了,挂成了10
因为是要乘好多次同一个只因数,而不是只因数乘上那个次数
#include <bits/stdc++.h>
#define ll long long
#define gt getchar
#define pt putchar
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=gt();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=gt();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=gt();}
return x*f;}
inline void print(ll x){if(x<0)pt('-'),x=-x;if(x>9)print(x/10);pt(x%10+48);}
void file(){freopen("buy.in", "r", stdin);freopen("buy.out", "w", stdout);}
const int Mod = 1e9 + 7;
int n;
int cnt[100005], bj[100005], tot;
map<int, bool> mp;
void r(int x) {
for (int i = 2; i * i <= x; i++)
{
if (x % i == 0)
{
int tim = 0;
while (x % i == 0) x /= i, ++ tim;
if(i <= 100000)cnt[i] = max(cnt[i], tim);
else bj[++ tot] = i;
}
}
if (x != 1)
{
if(x <= 100000)cnt[x] = max(cnt[x], 1);
else if(!mp[x])bj[++ tot] = x, mp[x] = 1;
}
}
int main()
{
//file();
n = read();
for(int i = 1; i <= n; ++ i)r(read());
ll res = 1;
for(int i = 1; i <= 100000; ++ i)
{
for(int j = 1; j <= cnt[i]; ++ j)
{
res = (res * i) % Mod;
}
}
for(int i = 1; i <= tot; ++ i)
{
res = (res * bj[i]) % Mod;
}
cout << res << '\n';
return 0;
}
T2
啥也不会
暴搜,然后存状态时将每个糖果压成一个整数即可,因为每个糖果只会在他们对应的行/列移动
再注意到每个点不一定要移动尽量多的步数
代码长死,也没写
T3
线段树,考虑答案的合并
左边维护后缀模 \(p\) 等于 \(?\) 的个数 \(???[?]\)
右边维护前缀模 \(?\) 等于 \(?\)
此时长度 \(?\) 满足 \(10^l \mod p = z\) 的有多少个 \(???[?][?]\)
考虑枚举 \(?, ?\),需要的 \(?\) 可以算出来
答案增加 \(???[?] × ???[?][(? − ? \times ?)%?]\) 即可