HDU 4432 Sum of divisors (进制模拟)
三个小函数
getdiv(); 求因子
getsum(); 求平方和
change(); 转换成该进制
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,cnt,ans,num;
int di[555555];
char str[111111];
void getdiv() {
int up = sqrt(n);
cnt = 0;
for(int i=1; i<=up; i++) {
if(n % i == 0) {
di[cnt++] = i;
if(n != i*i)
di[cnt++] = n/i;
}
}
} void getsum() {
ans = 0;
for(int i=0; i<cnt; i++) {
int tmp = di[i];
while(tmp) {
int t = tmp % m;
ans += t*t;
tmp = tmp / m;
}
}
} void change() {
num = 0;
while(ans) {
int t = ans % m;
if(t >= 10) {
str[num++] = t - 10 + 'A';
} else str[num++] = '0' + t;
ans = ans / m;
}
} int main() {
while(cin >> n >> m) {
getdiv();
getsum();
change();
for(int i=num-1; i>=0; i--) {
printf("%c",str[i]);
}
puts("");
}
return 0;
}
HDU 4432 Sum of divisors (进制模拟)的更多相关文章
- HDU 4432 Sum of divisors (水题,进制转换)
题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...
- hdu 4432 Sum of divisors(十进制转其他进制)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...
- HDU 4278 Faulty Odometer 8进制转10进制
Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 1335 Basically Speaking(进制转换)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...
- HDU 2097 sky数 (进制转化)
传送门: Sky数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDOJ(HDU) 1720 A+B Coming(进制)
Problem Description Many classmates said to me that A+B is must needs. If you can't AC this problem, ...
- HDU 2100 Lovekey (26进制大数、字符串)
Lovekey Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- hdu 2097 sky数(进制转换)
Sky数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 4278 Faulty Odometer(进制转换)
十进制转八进制的变形: #include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF& ...
随机推荐
- jQuery AJAX load() 方法
jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. load() 方法从服务器加载数据,并把返回的数据放入被选元素中. 语法: $(selector). ...
- jQuery慢慢啃之ajax(九)
1.jQuery.ajax(url,[settings])//通过 HTTP 请求加载远程数据 如果要处理$.ajax()得到的数据,则需要使用回调函数.beforeSend.error.dataFi ...
- OSPF + LVS ,突破LVS瓶颈 (转)
突破LVS瓶颈,LVS Cluster部署(OSPF + LVS) 前言 架构简图 架构优势 部署方法 1.硬件资源准备 2.三层设备OSPF配置 3.LVS调度机的OSPF配置 a.安装软路由软件q ...
- Git (2)
要使用Git首先遇到的问题是怎么把文件加到库中. 很简单. 新建一个目录,然后git init. 完成上述工作之后的唯一改动是在当前目录下生成了一个.git的子目录.这个子目录是一个集中的数据库,包含 ...
- WPF RadioButton & CheckBox Style
<Style TargetType="CheckBox"> <Setter Property="Template"> <Sette ...
- 如何在Webstorm中添加js库 (青瓷H5游戏引擎)
js等动态语言编码最大的缺点就是没有智能补全代码,webstorm做到了. qici_engine作为开发使用的库,如果能智能解析成提示再好不过了,经测试80%左右都有提示,已经很好了. 其他js库同 ...
- iscroll横向滑动(当前页状态标记自动变化)
var myScroll; function loaded(){ myScroll = new iScroll('wrapper',{ snap:true, checkDOMChanges:true, ...
- Php会员权限
<?phpecho $uu=@array_sum(@$_POST['gr']);?><form action="" method="POST" ...
- 关于手机端CSS Sprite图标定位的一些领悟
今天在某个群里面闲逛,看见一个童鞋分享了一个携程的移动端的页面.地址这里我也分享下吧:http://m.ctrip.com/html5/在手机端我都很少用雪碧图合并定位图标,用的比较多就是用字体图标来 ...
- mac+eclipse+svn+maven经验总结(转)
1.Eclipse for Mac:http://mirrors.ustc.edu.cn/eclipse/technology/epp/downloads/release/indigo/SR2/ecl ...