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. java面向对象编程思想的理解

    1.我们总说java是一门面向对象编程的语言,那什么是面向对象呢? 我是这样理解的,对象是事物存在的实体,如,猪.狗,花早等都是对象,对象由两部分组成.面向对象编程的三大特点:继承,多态,类是封装对象 ...

  2. c#数据库连接池Hikari重构升级

    Hikari是我自定义的数据库连接池,前面已经提供了地址.因为c#的连接池按照规范的ADO.NET里面实现定义的.由数据库官方提供,但是实现方式就不知道了,反正没有看出来,估计一般是连接类实现的,但是 ...

  3. 使用 form 和 iframe 实现图片上传回显

    主要利用 form 的 target 属性,在提交表单之后 response 返回到 iframe 中 form 的 action 可以自己写,也可以直接利用 富文本编辑器的接口实现上传 <fo ...

  4. vue组件中的样式属性--scoped

    Scoped CSS Scoped CSS规范是Web组件产生不污染其他组件,也不被其他组件污染的CSS规范. vue组件中的style标签标有scoped属性时表明style里的css样式只适用于当 ...

  5. ionic 做移动应用怎么样?

    看了很多网上的赞美性介绍后,我们选用了这个做开发,目前碰到的坑有: android, list界面上下滑动会lag ios下,当键盘弹出时,你可以选择整个页面scroll,也可以选择不scroll,但 ...

  6. 1. tty终端接收数据原理

    1. 串口接收数据原理(以“ls”命令为例) (1) 每个终端设备都有一个接收缓冲区,保存原始数据.shell程序一直在休眠,等待合适的字符: (2) 串口接收到'l'字符,把它保存下来: (3) 串 ...

  7. 第一次学习tornado小练习

    内容 这次是python的一个web框架,tornado,这个web框架在python的几个web框架中一个比较简单的web框架,刚开始接触python的时候就知道python有两个比较常用的web框 ...

  8. Java学习笔记十四:如何定义Java中的类以及使用对象的属性

    如何定义Java中的类以及使用对象的属性 一:类的重要性: 所有Java程序都以类class为组织单元: 二:什么是类: 类是模子,确定对象将会拥有的特征(属性)和行为(方法): 三:类的组成: 属性 ...

  9. 洛谷U32670 小凯的数字(比赛)

    题目网址 https://www.luogu.org/problemnew/show/U32670 题目背景 NOIP2018 原创模拟题T1 NOIP DAY1 T1 or DAY 2 T1 难度 ...

  10. OVERLAY(文字の上書き)

    OVERLAY 命令により.文字列が別の文字列によって上書きされます. OVERLAY c1 WITH c2 [ONLY str]. この命令により.項目 c1 のすべての位置のうち.str の中に出 ...