2014
01-26

Xiaoming has just come up with a new way for encryption, by calculating the key from a publicly viewable number in the following way:
Let the public key N = AB, where 1 <= A, B <= 1000000, and a0, a1, a2, …, ak-1 be the factors of N, then the private key M is calculated by summing the cube of number of factors of all ais. For example, if A is 2 and B is 3, then N = AB = 8, a0 = 1, a1 = 2, a2 = 4, a3 = 8, so the value of M is 1 + 8 + 27 + 64 = 100.
However, contrary to what Xiaoming believes, this encryption scheme is extremely vulnerable. Can you write a program to prove it?

There are multiple test cases in the input file. Each test case starts with two integers A, and B. (1 <= A, B <= 1000000). Input ends with End-of-File.
Note: There are about 50000 test cases in the input file. Please optimize your algorithm to ensure that it can finish within the given time limit.

There are multiple test cases in the input file. Each test case starts with two integers A, and B. (1 <= A, B <= 1000000). Input ends with End-of-File.
Note: There are about 50000 test cases in the input file. Please optimize your algorithm to ensure that it can finish within the given time limit.

2 2
1 1
4 7

Case 1: 36
Case 2: 1
Case 3: 4393

/*
* hdu2421/win.cpp
* Created on: 2012-11-2
* Author    : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
const int MOD = 10007;
const int _4MOD = 4 * MOD;
typedef long long LL;
typedef vector<pair<int, int> > Int_Pair;
void get_prime_table(int N, vector<int> &pt) {
vector<bool> ip;
ip.resize(N + 1);
fill(ip.begin(), ip.end(), true);
int i, j, s, t = N - 1;
for (i = 3; i <= N; i++) {
s = (int) sqrt(i);
for (j = 2; j <= s; j++) {
if (i % j == 0)    break;
}
if (j <= s) {            ip[i] = false; t--;        }
}
pt.resize(t);
t = 0;
for(int i = 2; i <= N; i++) {
if(ip[i]) {    pt[t++] = i;    }
}
}
void get_prime_factor(int N, Int_Pair &f, const vector<int> &p) {
int i, t, n, pl = p.size();
f.clear();
for(i = 0; i < pl; i++) {
t = p[i];
if(N % t == 0) {
n = 0;
while(N % t == 0) {
n++;    N /= t;
}
f.push_back(make_pair(t, n));
}
if(N == 1) {    break;    }
}
if(N > 1) {
f.push_back(make_pair(N, 1));
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
vector<int> prime_table;
get_prime_table(2000, prime_table);
int A, B, t = 1, n, ans;
LL temp;
while(scanf("%d%d", &A, &B) == 2) {
Int_Pair ip;
get_prime_factor(A, ip, prime_table);
ans = 1;
for(int i = 0, len = ip.size(); i < len; i++) {
n = (ip[i].second * (LL)B + 1) % _4MOD;
temp = ((n * n) % _4MOD) * (((n + 1) * (n + 1)) % _4MOD);
temp = (temp % _4MOD) / 4;
ans *= temp;
ans %= MOD;
}
printf("Case %d: %d\n", t++, ans);
}
return 0;
}