hdu2421(数学题)

154 篇文章 0 订阅
82 篇文章 0 订阅

Description

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
 


给你2个数A,B,范围为1到100万。N是A的B次方。设a1,a2,……ai为N的因子,设k1,k2……,ki为a1,a2,……ai的因子个数。求k1,k2……,ki的立方和。

主要在于题意理解,然后这题就是求立方和的公式了1^3 + 2^3 + …… n^3 = [n (n+1) / 2]^2

刚开始没理解题意总是wawawa!!!!!!后来看题解了才知道原来是题目意思理解错了!!!


#include <iostream>
#include<algorithm>
#include<memory.h>
using namespace std;
typedef __int64 ll;
const int maxn=1e6+100;
bool p[maxn];
int k=0,su[maxn];
void get()
{
    memset(p,1,sizeof(p));
    for(ll i=2;i<maxn;i++)
    {
        if(p[i]==1)
        {
            su[k++]=i;
            for(ll j=i*i;j<maxn;j+=i)
            p[j]=0;
        }
    }
}

ll get1(int n,int m)
{
    ll s=1,num;
    for(int i=0;su[i]*su[i]<=n&&i<k;i++)
    {
         num=0;
        if(n%su[i]==0)
        {
            while(n%su[i]==0)
            {
                num++;
                n/=su[i];
            }
        }
        num =( num *m  + 1) % 10007;
        num=num * (num + 1) / 2 % 10007;
        s= s* (num * num % 10007) % 10007;
        if(n == 1) break;
    }
    if(n>1)
    {
         num=1;
        num =( num * m + 1) % 10007;
        num=num * (num + 1) / 2 % 10007;
        s= s* (num * num % 10007) % 10007;
    }
    return s;
}

int main()
{
    int n;
    int m,o=1;
    get();
    //for(int i=0;i<100;i++)cout<<su[i]<<' ';
    while(cin>>n>>m)
    {
        ll s=get1(n,m);
       // cout<<s<<endl;
        cout<<"Case "<<o++<<": "<<s<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值