hdu2421(数学,因式分解素数筛)
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(数学,因式分解素数筛)的更多相关文章
- Prime Path素数筛与BFS动态规划
埃拉托斯特尼筛法(sieve of Eratosthenes ) 是古希腊数学家埃拉托斯特尼发明的计算素数的方法.对于求解不大于n的所有素数,我们先找出sqrt(n)内的所有素数p1到pk,其中k = ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- 素数筛 poj 2689
素数筛 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ...
- BestCoder Round #85 hdu5778 abs(素数筛+暴力)
abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...
- poj 3048 Max Factor(素数筛)
这题就是先写个素数筛,存到prime里,之后遍历就好,取余,看是否等于0,如果等于0就更新,感觉自己说的不明白,引用下别人的话吧: 素数打表,找出20000之前的所有素数,存入prime数组,对于每个 ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Light oj 1197 - Help Hanzo (素数筛技巧)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 给你a和b求a到b之间的素数个数. 先在小区间素数筛,大区间就用类似素数筛的想法 ...
- 素数筛&&欧拉筛
折腾了一晚上很水的数论,整个人都萌萌哒 主要看了欧拉筛和素数筛的O(n)的算法 这个比那个一长串英文名的算法的优势在于没有多次计算一个数,也就是说一个数只筛了一次,主要是在%==0之后跳出实现的,具体 ...
- SDUT Fermat’s Chirstmas Theorem(素数筛)
Fermat's Chirstmas Theorem Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 In a letter ...
随机推荐
- .net mvc里AutoMapper更为便捷的使用方法
前言:AutoMapper的下载安装我就不多说了,网上百度一大堆.今天我就说说它的更为简单的使用,什么叫更为简单呢?按照一般的使用方法,我们首先建DTO,然后建每个对应的Profile,然后还要把每个 ...
- POJ2823 滑动窗口
滑动最小(最大)值,模版题. 题意:给一个数列,给一个窗口大小k,顺序求每个窗口中最大值和最小值. 和挑战中的例题一模一样,就多了一个求最大,改个大于小于符号就行. 算法是利用双端队列: 以求最小值为 ...
- jenkins部署记录
环境规划 主机分配 192.168.2.139 : gitlab 192.168.2.141 : jenkins 192.168.2.142 : haproxy01 192.168.2.143 :ha ...
- 避免 ‘sudo echo xxxx >’ 时候 出现 “permission denied”
➜ ~ echo "/opt/nfs 10.10.10.*(rw,all_squash,sync)">>/etc/exports zsh: permission de ...
- 汇编:采用址表的方法编写程序实现C程序的switch功能
//待实现的C程序 1 void main() { ; -) { : printf("excellence"); break; : printf("good") ...
- 在Python中使用正则表达式去掉字符串里的html标签
有时候会获得一些带html标签的字符串,需要把html标签去掉,获得干净的字符串,这时候可以使用正则表达式. 代码如下: import re htmeString = '''<ul id=&qu ...
- JDK8 新特性
JDK8 新特性目录导航: Lambda 表达式 函数式接口 方法引用.构造器引用和数组引用 接口支持默认方法和静态方法 Stream API 增强类型推断 新的日期时间 API Optional 类 ...
- hive 学习系列三(表格的创建create-table)
表格创建: 语法 第一种建表的形式: 说明: temporary 临时表,在当前回话内,这张表有效,当回话结束,可以理解为程序结束,则程序终止. external 外部表, hdfs 上的表的文件,并 ...
- Ruby字符串的一些方法
最近因为公司需求开始看ruby,先从ruby的基本数据类型开始看 看到ruby的字符串类型string,发现ruby中的字符串单双引号是不一样的,这点和Python有那么点不一样 主要是我们对字符串进 ...
- 笔记-python-常见特殊变量
笔记-python-常见特殊变量 类似__xx,以双下划线开头的实例变量名,就变成了一个私有变量(private),只有内部可以访问,外部不能访问: 类似__xx__,以双下划线开头,并且以双下划线结 ...