AtCoder Beginner Contest - Div Game
Authors: Maggie Liu, Mohammad Nour Massri
We can prime factorize as . To achieve the maximum number of operations, for each prime , we should first choose , then and so on.
As we prime factorize and find the exponent of each prime, we can decrement the exponent by , then , and so on, as long as the exponent stays nonnegative. Each time we decrement the exponent, we can add to the answer.
Implementation
Time Complexity:
C++
#include <iostream>using namespace std;int main() {long long n;cin >> n;int ans = 0;// prime factorize nfor (long long p = 2; p * p <= n; p++) {
Java
import java.io.*;import java.util.*;public class Main {public static void main(String[] args) {Kattio io = new Kattio();long n = io.nextLong();int ans = 0;// prime factorize n
Python
n = int(input())ans = 0# prime factorization for nfor p in range(2, int(n**0.5)):e = 0while n % p == 0:n /= pe += 1# here p^e divides n
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!