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 ,即移动前后盒子编号 ...
随机推荐
- topcoder srm 693 div1 -3
1.给出一个$n$个顶点的无向带权图.其中顶点$i,i+1$之间存在边,$i,i+2$之间存在边.而且仅有这些边.现在删掉其中的一些边,剩下的边满足图仍然是2联通的情况下使得权值和最小? 思路:其实就 ...
- 百度搜索引擎取真实地址-python代码
代码 def parseBaidu(keyword, pagenum): keywordsBaseURL = 'https://www.baidu.com/s?wd=' + str(quote(key ...
- .net core mvc 错误信息显示 ModelState.AddModelError
关于ModelState.AddModelError错误信息不在前端页面显示问题.经过一位高人指定终于知道了为什么,在次写着警示自己看文档一定要仔细.再次感谢这为兄弟 https://www.cnbl ...
- (zhuan) Prioritized Experience Replay
Prioritized Experience Replay JAN 26, 2016 Schaul, Quan, Antonoglou, Silver, 2016 This Blog from: ht ...
- SQLite EF Core Database Provider
原文链接 This database provider allows Entity Framework Core to be used with SQLite. The provider is mai ...
- Linux下 网卡测速
参考: How do I verify the speed of my NIC? Linux下 网卡测速 命令: $ sudo ethtool eth0 Settings for eth0: Supp ...
- TCP/UDP协议、理解三次握手四次挥手、Socket
一.什么是socket? 中文名叫套接字,是对底层的 TCP IP UDP 等网络协议进行封装,使得上层的应用程序开发者,不用直接接触这对复杂,丑陋的协议. 在程序员的言论,他就是一个封装好的模块,要 ...
- NPOI导入导出EXCEL通用类,可直接使用在WinForm项目中
由于XSSFWorkbook类型的Write方法限制,Write完成后就自动关闭流数据,所以无法很好的支持的Web模式,网上目前也未找到好的解决方案. 注意:若直接使用在WinForm项目中,必需先下 ...
- 封装fetch的使用(包含超时处理)
// 1: 传统fetch操作 fetch('http://facebook.github.io/react-native/movies.json') .then((response) => r ...
- mysql索引使用
原文:http://www.jianshu.com/p/2b541c028157 索引是快速搜索的关键.MySQL索引的建立对于MySQL的高效运行是很重要的.下面介绍几种常见的MySQL索引类型.在 ...