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 ,即移动前后盒子编号 ...
随机推荐
- linux如何使make输出makefile中所有的规则和变量
答: make -p (会执行makefile,加入-q可以阻止makefile的执行)
- linux内核中的dquot是什么?
答:这个与磁盘配额管理(disk quota)有关,内核配置选项为CONFIG_QUOTA,使能此选项意味着可以设置每个用户的硬盘使用限制.
- 逆波兰表达式|2013年蓝桥杯A组题解析第六题-fishers
逆波兰表达式 正常的表达式称为中缀表达式,运算符在中间,主要是给人阅读的,机器求解并不方便. 例如:3 + 5 * (2 + 6) - 1 而且,常常需要用括号来改变运算次序. 相反,如果使用逆波兰表 ...
- (转) Read-through: Wasserstein GAN
Sorta Insightful Reviews Projects Archive Research About In a world where everyone has opinions, on ...
- (转) The Incredible PyTorch
转自:https://github.com/ritchieng/the-incredible-pytorch The Incredible PyTorch What is this? This is ...
- NLog——ElasticSearch——Kibana
Nlog.elasticsearch.Kibana以及logstash在项目中的应用(一) Nlog.elasticsearch.Kibana以及logstash在项目中的应用(二) ASP.NET ...
- Docker6之Network containers
how to network your containers. Launch a container on the default network Docker includes support fo ...
- Machine.config与web.config
应用范围的不同 结点介绍 原理介绍 异常 web.config详解
- Jenkins-pipeline
https://my.oschina.net/ghm7753/blog/371954?p=1
- 17秋 SDN课程 第一次作业
SDN第一次作业 你会选择作 网络编程 方向的程序员吗?为什么? 有可能.原因如下: 1.我的研究与网络密切相关: 2.SDN侧重软件实现,自然涉及socket等网络编程知识,属于基本功: 3.市场. ...