hdu-2421 Deciphering Password 数学姿势
给定A,B,对于A^B的每一个因子,M为其因子的因子数的三次方求和。
容易推导得出A^B的每一个因子都是A的质因子的组合(质因子可重复利用),其因子数自然等于所使用的每个质因子的数量乘积。
假设A由质因子a1,a2,a3组合而成,对应数量为k1,k2,k3,那么A的因子数为(k1+1)*(k2+1)*(k3+1),同理A的因子的因子数为(k1+1)*(k2+1)*k3+1,(k1+1)*k2*(k3+1),k1*(k2+1)*(k3+1),(k1+1)*k2*k3以此类推。
我们可以发现其为(1+2+3...k1+1)*(1+2+3...k2+1)*(1+2+3...k3+1)的展开。对于这里的每一项,我们可以用求和公式(n*(n+1)/2)^2来求解。
对于拆解一个数的质因数,我们只需要枚举到srqt(n)即可,因为至多只有一个质因数大于sqrt(n) n不断做除法剩下的数即是这个质因数,如果有两个质因数x1,x2大于sqrt(n),那一定有n>=x1*x2与x1>sqrt(n) x2>sqrt(n)相悖。
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const LL N = ;
const LL mod = ;
LL cube(LL num)
{
return (num*(num + ) / )%mod*(num*(num + ) / );
}
vector<LL> su;
bool vis[N];
int main() {
//cin.sync_with_stdio(false);
LL a,b;
fill(vis, vis + N, true);
vis[] = vis[] = false;
for(LL i=;i<N;i++)
if (vis[i])
{
su.push_back(i);
for (LL j = i * ; j < N; j *= i)
vis[i] = false;
}
int cas = ;
while (scanf("%lld%lld",&a,&b)!=EOF)
{
map<LL, LL> mp;
for (LL i = ; i < su.size() && su[i]*su[i] <= a; i++)
{
while (a%su[i] == )
cout << su[i] << endl, mp[su[i]]++, a /= su[i];
}
if (a > )mp[a]++;
LL ans = ;
for (map<LL, LL>::iterator it = mp.begin(); it != mp.end(); it++)
{
it->second *= b, it->second++;
it->second %= mod;
//cout << it->second << endl;
ans *= cube(it->second);
ans %= mod;
}
printf("Case %d: %lld\n", cas++, ans);
//cout << "Case " << cas++<<": ";
//cout << ans << endl; } return ;
}
hdu-2421 Deciphering Password 数学姿势的更多相关文章
- hdu 2421 Deciphering Password(约数个数问题)
http://acm.hdu.edu.cn/showproblem.php?pid=2421 A^B 能够写成 p1^e1 * p2^e2 * .....*pk^ek.(A.B <= 10000 ...
- HDU 2825 Wireless Password (AC自己主动机,DP)
pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...
- HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...
- HDU 5584 LCM Walk 数学
LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...
- HDU 4336 Card Collector 数学期望(容斥原理)
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...
- HDU 5750 Dertouzos 简单数学
感悟:这又是zimpha巨出的一场题,然后04成功fst(也就是这题) 实际上还是too young,要努力增加姿势, 分析:直接枚举这些数不好枚举,换一个角度,枚举x*d,也就是d的另一个乘数是多少 ...
- HDU 5570 balls 期望 数学
balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5570 De ...
- hdu 2825 Wireless Password(ac自己主动机&dp)
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 4710 Balls Rearrangement (数学思维)
意甲冠军:那是, 从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号 ...
随机推荐
- 上传svn失败,代码冲突解决方式
1,修改文件后提交不了,大多是因为版本不一致造成的.更新一下,不产生冲突的情况,就可以提交了. 2,更新文件,如果出现冲突的情况,打开冲突文件test.php会看到类似以下的内容 <<&l ...
- Array数组集合的排序
/* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...
- Linux 搭建 Jenkins
环境准备 安装JDK 安装 JDK 之前写过一篇文章,本文就不具体讲了: Linux 安装 JDK 注意:Java版本不能是gcj,会导致Jenkins有问题,centos7搭建jenkins小记文章 ...
- Django 创建项目笔记
基本命令 mkdir mysite # 创建项目目录,常取名mysite cd mysite virtualenv env # env\Scripts\activate.bat # Win pip i ...
- 题解——loj6278 数列分块入门2 (分块)
查询小于k的值 注意lower_bound一定要减去查找的起始位置得到正确的位置 调了快两天 淦 #include <cstdio> #include <algorithm> ...
- Bytom猜谜合约使用指南
准备工作: 1.安装全节点钱包V1.0.5以上并同步完成: 2.已经发行一种资产,发行资产的方法具体见文章<如何在Bytom上发布资产?> 3.准备好一些BTM作为手续费: 设置谜语(锁定 ...
- Docker:Containers
Prerequisites Install Docker version 1.13 or higher. Read the orientation in Part 1. Give your envir ...
- Katana的WebAPI集成Swagger 解决方案
这位大哥写的博客很清楚了,我就不重复了. http://www.cnblogs.com/caodaiming/p/4156476.html 错误解决 http://blog.csdn.net/gold ...
- 3、Python函数详解(0601)
回顾: re search,findall,finditer.sub,subn function () 调用函数 def func_name(arg1,....) 生成函数对象 func_s ...
- 【NOIP 2016】Day2 T3 愤怒的小鸟
Problem Description \(Kiana\) 最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于 \((0,0)\) 处,每次 \(Kiana\ ...