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 ...
随机推荐
- 一站式学习Redis 从入门到高可用分布式实践(慕课)第六章 Redis开发运维常见问题
fork操作 1.同步操作 2.与内存量息息相关:内存越大,耗时越长(与机器类型有关) 3.info:latest_fork_usec 进程外开销 AOF追加阻塞 不知道哪个命令??? 单机多实例部署 ...
- Plupload+easyui+springmvc实现批量上传
demo下载(java项目):http://pan.baidu.com/s/1ntmoGEd 可兼容所有常用浏览器,当前版本为V1.5.4,如果不兼容,肯定是你没有调试好啊 1.jsp代码 <% ...
- Evercookie
1. Evercookie Evercookie是一个Javascript API,可以在浏览器中生成极其持久的cookie. 它的目标是在客户删除标准cookie,Flash cookie(本地共享 ...
- C++指针数组,二级指针和函数指针的练习
1.编一程序,将字符串“Hello,C++!”赋给一个字符数组, 然后从第一个字母开始间隔地输出该串(请用指针完成). 代码如下 #include<iostream> #include&l ...
- jQuery Ajax请求后台数据并在前台接收
1.ajax基本语法 <script> $(function(){ $('#sub').click(function(){ var username=$('#username').val( ...
- 前后端不分离部署教程(基于Vue,Nginx)
有小伙伴私信问我vue项目是如何进行前后端不分离打包发布的,那我岂能坐视不管,如此宠粉的我肯定是要给发一篇教程的,话不多说,开始操作 前端假如我们要发布我们的Vue项目,假设我们前端用的是histor ...
- Sencha Themer
Sencha Themer 1:介绍 在Ext JS中创建自定义主题一直是一项挑战.但是使用Sencha Themer,我们已经删除了所有的猜测工作,并添加了一个简单的图形界面来定制应用程序的任何方面 ...
- IDEA开发vue.js卡死问题
在执行cnpm install后会在node_modules这个文件下面生成vue的相关依赖文件, 这个时候当执行cnpm run dev命令时,会导致IDEA出现卡死的问题,解决方法如下:
- STM32CubeMx配置USART注意的一个问题
HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, Number);意思是接收到Number个字节后,触发HAL_UART_RxCpltCal ...
- crest value &minimum
public class paixu { public static void main(String[] args) { double temp; double num[]={5.1, 7.12, ...