hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)
Deciphering Password
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2357 Accepted Submission(s):
670
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?
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.
in the format as indicated in the sample output.
1 1
4 7

#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-(欧拉筛+唯一分解定理+积性函数+立方求和公式)的更多相关文章
- 2018南京icpc-J-Prime Game (欧拉筛+唯一分解定理)
题意:给定n个数ai(n<=1e6,ai<=1e6),定义,并且fac(l,r)为mul(l,r)的不同质因数的个数,求 思路:可以先用欧拉筛求出1e6以内的所有质数,然后对所有ai判断, ...
- hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 【BZOJ 2749】 2749: [HAOI2012]外星人 (数论-线性筛?类积性函数)
2749: [HAOI2012]外星人 Description Input Output 输出test行,每行一个整数,表示答案. Sample Input 1 2 2 2 3 1 Sample Ou ...
- hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- noip复习——线性筛(欧拉筛)
整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...
- [模板] 积性函数 && 线性筛
积性函数 数论函数指的是定义在正整数集上的实或复函数. 积性函数指的是当 \((a,b)=1\) 时, 满足 \(f(a*b)=f(a)*f(b)\) 的数论函数. 完全积性函数指的是在任何情况下, ...
- 欧拉筛,线性筛,洛谷P2158仪仗队
题目 首先我们先把题目分析一下. emmmm,这应该是一个找规律,应该可以打表,然后我们再分析一下图片,发现如果这个点可以被看到,那它的横坐标和纵坐标应该互质,而互质的条件就是它的横坐标和纵坐标的最大 ...
- 【BZOJ 2190】【SDOI 2008】仪仗队 欧拉筛
欧拉筛模板题 #include<cstdio> using namespace std; const int N=40003; int num=0,prime[N],phi[N]; boo ...
- [51NOD1181]质数中的质数(质数筛法)(欧拉筛)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1181 思路:欧拉筛出所有素数和一个数的判定,找到大于n的最小质 ...
随机推荐
- 模拟python中的Yield伪并发
并发,在操作系统中,是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行. #Yield伪并发 _author_= ...
- mysql存储过程的编写
1.MySQL 新增存储过程,因为mysql默认以:为分隔符,该分隔符会使mysql自动执行sql语句,故需要将分隔符修改下,下面通过DELIMITER设为$$,然后编写SQL,编写完成再将:设为分隔 ...
- vue的异步组件按需加载
当build打包后,app.js过大的时候,可以考虑用异步组件的方式. import HomeHeader from "./components/Header"; import H ...
- redis的哨兵集群,redis-cluster
#主从同步redis主从优先1.保证数据安全,主从机器两份数据一主多从2.读写分离,缓解主库压力主redis,可读可写slave身份,只读 缺点1.手动主从切换假如主库挂了,得手动切换master ...
- 关于transition和animation
最近的工作以移动端项目居多,经常会涉及一些比较小的动画效果,所以使用css3设计动画效果也就越发熟练起来.但是不得不承认,一直以来都是凭感觉使用transform, transition, anima ...
- 零基础学习python_字符串(14-15课)
今天回顾下我之前学习python的第一个对象——字符串,这个对象真蛋疼,因为方法是最多的,也是最常见的类型,没有之一... 内容有点多,我就搜了下网上的资料,转载下这个看起来还不错的网址吧:http: ...
- qt 软件打包
今天呈现的客户端完成了要打包发布,想了一下还不会,就问了一下度娘,在此记录一下学习的程度 1>将QT编译工具的BUG模式切换成Release模式,在Release模式下生成一个*.exe的可执行 ...
- MySQL----ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
1.问题描述 在导入同事提供的一个sql文件时候,出现了一个1071错误,总结学习一下: 2.分析问题 错误的字面意思是说mysql字段设置的值太长了,不能大于767个字节,在网上找了一些资料后才知道 ...
- oracle 服务名 数据库名 实例名
服务名 show parameter service_name 实例名 show parameter instance 数据库名 show parameter db conn username/pas ...
- Linux下zip命令
解压命令(解压.覆盖解压) unzip zip unzip -o xxx.zip 压缩命令(支持多个文件或目录) zip -r xxx.zip xxx yyy.txt /a/b/c