TopCoder

Thumb hsnu2016
Adrien Wu
$ \begin{align} AC \times 2^9 \\ \text{New TIOJ ?} \end{align} $

User's AC Ratio

100.0% (4/4)

Submission's AC Ratio

66.7% (4/6)

Description

Original Description

給你 $N$ 個正整數,第 $i$ 個數字為 $a_i$ ,請你計算 $S = a_1 \times a_2 \times a_3 \times ...... \times a_N$ 這個數字中,有幾個因數。因數個數可能會非常大,所以請你算出因數個數除 $880301$ 的餘數。

其中,對於每個 $i$ ,$a_i$這個數只能擁有 $3$ 或 $4$ 或 $5$ 個不同的 因數

$880301$ 是個質數喔。

Original Input Format

輸入的第一行包含一個正整數 $N$ ,代表正整數的個數。

接下來的一行,包含 $N$ 個整數,第 $i$ 個正整數為 $a_i$ 。

  • $1 \le N \le 100$
  • $1 \le a_i \le 1000$

Original Output Format

請輸出一個數字,代表 $S$ 的因數個數。輸出這個數字除 $880301$ 的餘數。

Original Sample Input

Sample Input 1:
3
9 15 143

Sample Input 2:
3
4 8 16

Original Sample Output

Sample Output 1:
32

Sample Output 2:
10

Original Limits

  • Time Limit: 1 second
  • Memory Limit: 256 MB

Program To Be Hacked

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

map<ll,ll> mp; //prime number --> the occurence of this prime

ll a[106];

void f1(int num,int cnt) {
    for (int i=2;i<=num;++i) {
        while (num % i == 0) {
            mp[i] += cnt;
            num /= i;
        }
    }
}

bool is_p[1006];

int main () {
    for (int i=2;i<1006;++i) {
        if (!is_p[i]) {
            for (int j=i+i;j<1006;j+=i) is_p[j] = true;
        }
    }
    //is_p[i] == false means i is a prime
    int n;
    cin >> n;
    for (int i=0;i<n;++i) {
        cin >> a[i];
    }
    for (int times=0;times<100;++times) {
        for (int i=0;i<n;++i) {
            for (int j=i+1;j<n;++j) {
                ll gcd = __gcd(a[i],a[j]);
                if (gcd != 1) {
                    int cnt=0;
                    for (int k=0;k<n;++k) {
                        if (a[k]%gcd == 0) {
                            cnt++;
                            a[k] /= gcd;
                        }
                    }
                    f1(gcd,cnt);
                }
            }
        }
    }
    //after the process above, numbers left must be one of the following forms: p, p^2, p^3, p^4, p*q, and every prime factor in a[i] are distinct!!!
    for (int i=0;i<n;++i) {
        if (a[i] != 1) {
            for (int x=2;x<=40;++x) {
                if (x*x*x*x == a[i]) {
                    a[i] = 1;
                    mp[x] += 4;
                    break;
                }
                if (x*x*x == a[i]) {
                    a[i] = 1;
                    mp[x] += 3;
                    break;
                }
                if (x*x == a[i]) {
                    a[i] = 1;
                    mp[x] += 2;
                    break;
                }
            }
            if (a[i] != 1) {
                if (!is_p[ a[i] ]) mp[ a[i] ]+=1;
                else {
                    //since I do not know what exactly p & q is, so I assume that one is a[i], the other is -a[i]
                    mp[ a[i] ]  = 1;
                    mp[ -a[i] ] = 1;
                }
            }
        }
    }
    ll ans=1;
    for (auto i:mp) {
        ans *= (i.second+1);
        ans %= 880301;
    }
    cout << ans << endl;
}

Judge Method

請輸出一筆測試資料,使得上述的程式碼會輸出錯的答案。

Sample Code

以下程式碼能產生本題合法但一定不會讓你得到 AC 的測試資料。

#include <cstdio>
int main() {
    printf("3\n4 8 16\n");
}

Input Format

Output Format

Sample Input

Sample Output

Hints

Problem Source

Subtasks

No. Testdata Range Score
1 0 1

Testdata and Limits

No. Time Limit (ms) Memory Limit (KiB) Output Limit (KiB) Subtasks
0 1000 262144 262144 1