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 
 
这个题的题意就是求n=a的b次方,数n的各个质因数的立方和;题目给出的a,b范围是100万,所以就要采取特殊的办法了;

这个:质数的N次方会有N+1个因子,大家知道吧(为什么呢,自己慢慢体会);然后这个n就可以分解为多个质数的次方的

乘积;比如f(n)=f(c^x*d^y); 原本题意是各个质因数的立方和其实就等于1的立方和加到n的因子个数的立方和;这里给出公式是

(n*(n+1)/2)^2; 那么因为f(n)=f(c^x*d^y);==1到c^x的立方*1到d^y的因子个数立方和;自己慢慢体会qaq
代码

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

hdu2421(数学,因式分解素数筛)的更多相关文章

  1. Prime Path素数筛与BFS动态规划

    埃拉托斯特尼筛法(sieve of Eratosthenes ) 是古希腊数学家埃拉托斯特尼发明的计算素数的方法.对于求解不大于n的所有素数,我们先找出sqrt(n)内的所有素数p1到pk,其中k = ...

  2. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

  3. 素数筛 poj 2689

    素数筛 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ...

  4. BestCoder Round #85 hdu5778 abs(素数筛+暴力)

    abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...

  5. poj 3048 Max Factor(素数筛)

    这题就是先写个素数筛,存到prime里,之后遍历就好,取余,看是否等于0,如果等于0就更新,感觉自己说的不明白,引用下别人的话吧: 素数打表,找出20000之前的所有素数,存入prime数组,对于每个 ...

  6. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  7. Light oj 1197 - Help Hanzo (素数筛技巧)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 给你a和b求a到b之间的素数个数. 先在小区间素数筛,大区间就用类似素数筛的想法 ...

  8. 素数筛&&欧拉筛

    折腾了一晚上很水的数论,整个人都萌萌哒 主要看了欧拉筛和素数筛的O(n)的算法 这个比那个一长串英文名的算法的优势在于没有多次计算一个数,也就是说一个数只筛了一次,主要是在%==0之后跳出实现的,具体 ...

  9. SDUT Fermat’s Chirstmas Theorem(素数筛)

    Fermat's Chirstmas Theorem Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 In a letter ...

随机推荐

  1. zepto 基础知识(1)

    1.$() 的用法. 获取元素 $('div') //获取所有页面中的div元素 $('#foo') // 获取ID 为"foo"的元素 创建元素 $("<p> ...

  2. C#提取html中的汉字

    using System.Text.RegularExpressions; private string StripHT(string strHtml) //从html中提取纯文本 { Regex r ...

  3. FBI树

    题目描述 我们可以把由"0"和"1"组成的字符串分为三类:全"0"串称为B串,全"1"串称为I串,既含"0&q ...

  4. python 如何在列表list,字典dict,集合set 中根据条件筛选数据

    from random import randint """ list 过滤掉负数 """ data = [randint(-10, 10) ...

  5. 修改pytorch官方实例适用于自己的二分类迁移学习项目

    本demo从pytorch官方的迁移学习示例修改而来,增加了以下功能: 根据AUC来迭代最优参数: 五折交叉验证: 输出验证集错误分类图片: 输出分类报告并保存AUC结果图片. import os i ...

  6. python之打印九九乘法表

    配置环境:python 3.6 python编辑器:pycharm 整理成代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- #九九乘法表 #分析:九 ...

  7. python3 练习题100例 (二十一)打印一定范围内的水仙花数

    题目内容: 水仙花数是指一个n位数 (n≥3),它的每个位上的数字的n次幂之和等于它本身. 例如:153是一个“水仙花数”,因为 153 是个 3位数,而1**3+5**3+3**3==153. 输入 ...

  8. python中 列表常用的操作

    列表可以装大量的数据,不限制数据类型,表示方式:[]:列表中的元素用逗号隔开. lst = [] #定义一个空列表 lst = ["Tanxu",18,"女", ...

  9. pwa学习笔记--简介

    1. 介绍 Progressive Web App , (渐进式增强 WEB 应用) 简称 PWA ,是提升WebApp的体验的一种新方法,能给用户原生应用的体验. PWA 本质上是 Web App ...

  10. hoj第三场G-manhattanp ositioning system

    ---恢复内容开始--- 一.题意 在二维坐标系内,给定若干个点和目标点距离该点的曼哈顿距离,求是否存在唯一解使得目标点坐标为整数. 二.题解 重新思考题目模型,考虑曼哈顿距离一定时,几何含义为,以给 ...