Deciphering Password

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2357    Accepted Submission(s):
670

Problem 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 = AB, where 1 <= A, B <=
1000000, and a0, a1, a2, …, ak-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 =
AB = 8, a0 = 1, a1 = 2, a2 = 4,
a3 = 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
 
翻译:输入a和b,n=a^b,求n的因子有哪些,这些因子又有多少个因子数,对于这些因子数的立方和累加
 
唯一分解定理
定义:任何一个数可以表示成 素数的次方 的乘积
分解公式: 
求N的因子个数公式 num=(a1+1)*(a2+1)*......*(an+1);
 
积性函数
对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数
 
素数的之间互质,素数的幂次方也互质
对于求因子个数,也是积性函数
素数的n次方有(n+1)个因子,并且这些因子的因子个数从1到n+1递增,这就可以套用1到n的立方和公式
比如3^4=81,因子有1,3,9,27,81
 1-1
 3-1,3
 9-1,3,9
27-1,3,9,27
81-1,3,9,27,81
AC代码:
注:这段代码比较玄,用c++提交WA,用g++提交能AC,中间有一句避免多次循环找大素数没有加上的话,c++提交WA,g++提交TLE
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
#define ll long long
const int p=;
const int maxx=1e6+;
ll a,b;
int prime[maxx];
bool vis[maxx];
int cnt;
void init()///欧拉筛
{
cnt=;
memset(vis,true,sizeof(vis));
vis[]=vis[]=false;
for(int i=;i<=maxx;i++)
{
if(vis[i])
prime[cnt++]=i;
for(int j=;j<cnt && prime[j]*i<=maxx;j++)
{
vis[ i*prime[j] ]=false;
if( i%prime[j]== ) break;///prime[j]必定是prime[j]*i和i的最小质因子
}
}
}
ll sum(ll n)///立方和公式
{
return ( (n*n+n)/ )%p * ( (n*n+n)/ )%p;
} int main()
{
init();
int x=;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
ll ans=;
if(vis[a])//a是素数,则直接求,节省时间
ans=sum(+b);
else
{//prime[i]*prime[i]<=a;不加就会超时,大素数的因子一般只有一个,没必要一个一个找,也可以改成!vis[a],都是避免多次循环找大素数
for(int i=; i<cnt && prime[i]*prime[i]<=a; i++)
{
int num=;
if(a==) break;
while(a%prime[i]==)
{
a=a/prime[i];
num++;
}
if(num!=)
{
ans*=sum(num*b+);//积性函数
ans%=p;
}
}
if(a!=)///应对大素数的情况
{
ans*=sum(b+);
ans%=p;
}
}
printf("Case %d: %lld\n",++x,ans%p);
}
return ;
}
/*
手撸36=2^2 * 3^2 ans=(1^3 + 2^3 +3^3)^2=1296
36的因子有 1 2 3 4 6 9 12 18 36
对应的因子数 1 2 2 3 4 3 6 6 9
累加后也是1296
*/
 

hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)的更多相关文章

  1. 2018南京icpc-J-Prime Game (欧拉筛+唯一分解定理)

    题意:给定n个数ai(n<=1e6,ai<=1e6),定义,并且fac(l,r)为mul(l,r)的不同质因数的个数,求 思路:可以先用欧拉筛求出1e6以内的所有质数,然后对所有ai判断, ...

  2. hdu3826-Squarefree number-(欧拉筛+唯一分解定理)

    Squarefree number Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. 【BZOJ 2749】 2749: [HAOI2012]外星人 (数论-线性筛?类积性函数)

    2749: [HAOI2012]外星人 Description Input Output 输出test行,每行一个整数,表示答案. Sample Input 1 2 2 2 3 1 Sample Ou ...

  4. hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  5. noip复习——线性筛(欧拉筛)

    整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...

  6. [模板] 积性函数 && 线性筛

    积性函数 数论函数指的是定义在正整数集上的实或复函数. 积性函数指的是当 \((a,b)=1\) 时, 满足 \(f(a*b)=f(a)*f(b)\) 的数论函数. 完全积性函数指的是在任何情况下, ...

  7. 欧拉筛,线性筛,洛谷P2158仪仗队

    题目 首先我们先把题目分析一下. emmmm,这应该是一个找规律,应该可以打表,然后我们再分析一下图片,发现如果这个点可以被看到,那它的横坐标和纵坐标应该互质,而互质的条件就是它的横坐标和纵坐标的最大 ...

  8. 【BZOJ 2190】【SDOI 2008】仪仗队 欧拉筛

    欧拉筛模板题 #include<cstdio> using namespace std; const int N=40003; int num=0,prime[N],phi[N]; boo ...

  9. [51NOD1181]质数中的质数(质数筛法)(欧拉筛)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1181 思路:欧拉筛出所有素数和一个数的判定,找到大于n的最小质 ...

随机推荐

  1. Spring MVC与注解相关的一些配置的方法

    在spring mvc中,注解是需要通过配置文件去开启的,一般简单的项目可分为两个配置文件,这里姑且叫做spring-mvc.xml与spring-context.xml.其中spring-mvc.x ...

  2. mySQL InnoDB 的性能问题讨论

    https://ncisoft.iteye.com/blog/34676 https://www.douban.com/note/245895324/ MySQL最为人垢病的缺点就是缺乏事务的支持,M ...

  3. 微信小程序笔记<一>初识小程序

    一.IDE界面介绍 编辑界面 调试界面 项目管理界面 左侧工具介绍 二.项目文件类型及结构介绍 这是一个初始小程序的项目目录,其中涉及四种文件类型: *.js:JavaScript文件(JavaScr ...

  4. 项目经验分享[转自min.jiang]

        最近三个月,我非常荣幸的做为TeamLeader带领几个小组成员做了一个国外项目,这里想为大家分享一些小经验,尽管我佣有六年多的项目经验,但我一直的方向是架构师.大家知道架构师一般情况是偏向技 ...

  5. Exchange重启脚本

    Much more from the source article itself ...... details or code stated above http://therealshrimp.bl ...

  6. GPUImage中饱和度调整的实现——GPUImageSaturationFilter

    饱和度saturation,是指色彩的鲜艳程度,也称色彩的纯度.饱和度取决于该色中含色成分和消色成分(灰色)的比例.含色成分越大,饱和度越大:消色成分越大,饱和度越小.纯的颜色都是高度饱和的,如鲜红, ...

  7. beego注解路由 [自定义方法]

    背景: beego生成的controller里面,默认get请求到由Get()方法处理:post请求由Post()方法处理 etc. 如果想自定义方法来处理请求,改怎么做? 直接拿beego的文档来说 ...

  8. synchronized 和 lock 的区别

    1.Lock不是Java语言内置的,synchronized是Java语言的关键字,因此是内置特性.Lock是一个类,通过这个类可以实现同步访问: 2.Lock和synchronized有一点非常大的 ...

  9. vue eslint 代码自动格式化

    vue-cli 代码风格为 JavaScript Standard Style 代码检查规范严格,一不小心就无法运行,使用eslint的autoFixOnSave可以在保存代码的时候自动格式化代码 V ...

  10. 爬虫--Scrapy框架课程介绍

    Scrapy框架课程介绍: 框架的简介和基础使用 持久化存储 代理和cookie 日志等级和请求传参 CrawlSpider 基于redis的分布式爬虫 一scrapy框架的简介和基础使用 a)    ...