---
id: 479
lang: en
translation_of: index.md
source_sha256: 73b6b530b9cb6f4f6cd6e3b36e3e69c0231b811b2964180ab707248402922612
title: "P1069: Cell Division — Solution"
description: "We only need to analyze how the prime factors of each number relate to those of m1, and stop if a number lacks any prime factor of m1."
tags: ["OI","NOIP","Math"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "Problem name 细胞分裂 rendered as “Cell Division”."
  - "The condition in the problem summary is incomplete in the original (no “= 0” after the mod); kept as written."
  - "Heading 思路转化 (literally “idea transformation”) rendered as “Transforming the Problem”."
---

## Transforming the Problem

The problem is roughly this: given the numbers $N$, $m_1$, $m_2$, $S_{i[1\dots N]}$, find the smallest $t$ such that some $S_i^t \; mod\; m_1^{m_2}$.

So from there on it's very obvious: we just need to analyze how the prime factors of each number relate to the prime factors of $m_1$. If a number $c$ has the prime factor set $A$, then we can iterate over the prime factor set of $m_1$ and record the answer. If the prime factor set doesn't contain the prime factor set of $m_1$, exit right away.

## Code

```cpp
// P1069.cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int MX_N = 30020, INF = 0x3f3f3f3f;
ll n, m1, m2, arr[MX_N], pipePrime[MX_N], cellPrime[MX_N], lit, ans = INF;
int main()
{
    scanf("%lld%lld%lld", &n, &m1, &m2);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &arr[i]);
    if (m1 == 1)
    {
        printf("0");
        return 0;
    }
    for (int i = 2; m1 != 1; i++)
    {
        while (!(m1 % i))
            m1 /= i, pipePrime[i] += m2;
        lit = max(lit, (ll)i);
    }
    for (int i = 1; i <= n; i++)
    {
        ll now = 0;
        for (int j = 2; j <= lit; j++)
            if (pipePrime[j] != 0)
            {
                ll tim = 0;
                while (!(arr[i] % j))
                    arr[i] /= j, tim++;
                if (!tim)
                {
                    now = INF;
                    break;
                }
                now = max(now, (pipePrime[j] - 1) / tim);
            }
        ans = min(ans, now);
    }
    if (ans != INF)
        printf("%lld", ans + 1);
    else
        printf("-1");
    return 0;
}
```
