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 ,即移动前后盒子编号 ...
随机推荐
- git初学
git在团队合作开发时是很有用的,SVN是集中式的代表,而git是分布式的代表,它分为代码区.暂存区.和本地库.在同一个团队中开发时,在代码存储中心(例如,码云.github)上创建一个库,用于储存和 ...
- 【团队】EasyKing的实现_1
完成部分 三个功能类 英雄. 子弹. 瓦片地图. 一个设置类 地图 实现功能 瓦片地图 英雄移动 攻击 受到攻击 TODO 子弹攻击范围 地图.建筑物和英雄的碰撞箱 音效 英雄技能 建筑 双人联机 物 ...
- Images之multi-stage builds
原文链接 Use multi-stage builds Multi-stage builds are a new feature requiring Docker 17.05 or higher on ...
- win10 右键菜单很慢的解决方式
本来想用 win7 的,不想花很多时间折腾了.现在新电脑主板硬盘CPU都在排挤 win7 ,真是可怜呀.正题: 新电脑的性能应该还算不错的, 18 年跑分 29w 以上,但在图标上面右键却都要转圈几秒 ...
- 【译】第23节---Fluent API - 实体映射
原文:http://www.entityframeworktutorial.net/code-first/configure-entity-mappings-using-fluent-api.aspx ...
- ECMAScript6语法重点(二)
十一.Proxy和Reflect(Proxy保护对象不被外界访问:Object方法移植到Reflect) ①Proxy:原始对象(供应商)通过Proxy(代理商)生成新对象(映射原对象),用户访问的是 ...
- codeforces 768E Game of Stones
题目链接:http://codeforces.com/problemset/problem/768/E NIM游戏改版:对于任意一堆,拿掉某个次数最多只能一次. 对于一堆石头数量为$X$.找到一个最小 ...
- 字符串函数 mysql 和sqlserver 中对于字符串的常用函数和区别
1. 对于字符串大小写的统一 mysql和sqlserver中都有同名函数lower()和upper(),但是mysql中还有另外一对函数,达到同样的目的,lcase()和ucase(),也就是英文中 ...
- [原][osg]Geometry详解
//geometry成员变量 PrimitiveSetList _primitives; osg::ref_ptr<Array> _vertexArray; //顶点 osg::ref_p ...
- git的安装以及生成ssh key
安装git 在ubuntu系统下输入以下命令安装git软件: sudo apt-get install git 输入以下命令查看git是否安装成功: git --version 如下图所示则表示安装成 ...