hdu2421 (mathematics, factorization prime number sieve)

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 = A B, where 1 <= A, B <= 1000000, and a 0, a 1, a 2, …, a k-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 = A B = 8, a 0 = 1, a 1 = 2, a 2 = 4, a 3 = 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?

 
Input

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.

 
Output

For each test case, output the value of M (mod 10007) in the format as indicated in the sample output.

 
Sample Input

2 2
1 1
4 7 
 
Sample Output

Case 1: 36
Case 2: 1
Case 3: 4393 
 
The meaning of this question is to find the b power of n=a, the sum of the cubes of the prime factors of n; the range of a and b given by the question is 1 million, so special measures must be taken;

This: the N-th power of a prime number will have N+1 factors, everyone knows it (why, you will experience it slowly); then this n can be decomposed into multiple prime numbers to the power of

Product; such as f(n)=f(c^x*d^y); The original meaning of the title is that the sum of the cubes of each prime factor is actually equal to the cube of 1 and the sum of the cubes of the number of factors added to n; here is given The formula is

(n*(n+1)/2)^2; then because f(n)=f(c^x*d^y);==1 to the cube of c^x*1 to the factors of d^y Count the sum of cubes; slowly understand the qaq
code by yourself

#include <iostream>  
#include <cmath>  
#include <cstring>  
#include <cstdio>  
using namespace std;  
#define mod 10007 
int p[100010]; 
int prim[100010]; 
int len=0; 
void isp() //素数筛
{
     memset(p,0,sizeof(p)); 
    p[0]=1;p[1]=1;p[2]=0;
     for(int i=0;i<10000;i++)
    {
         if(p[i])
             continue;
         for(int j=i;j*i<10000;j++)
         {
             p[i*j]=1;
         }
         prim [len ++] = i;
     }
 
 }
intmain ()
{
    isp();
    long long cur=1;
    long long ans=1;
    long long a,b;
    while(cin>>a>>b)
    {
        ans=1;
        for(int i=0;prim[i]*prim[i]<=a;i++)
        {   long long sum=1;
            int j=0;
            if(a%prim[i]==0)
            {
                while(a%prim[i]==0)
                {
                    a/=prim[i];
                    j++;
                }
                sum=(b*j+1)*(b*j+2)/2%mod;
                I am _
                ans =ans*sum% mod;
            }
        }
        if(a>1)
        {
            long  long sum= 1 ;
            sum=(b+1)*(b+2)/2%mod;
                I am _
                ans =ans*sum% mod;
        }
        
        printf("Case %lld: %lld\n",cur++,ans); 
    }
    return 0;  
}  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325220010&siteId=291194637