三个小函数

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 (进制模拟)的更多相关文章

  1. HDU 4432 Sum of divisors (水题,进制转换)

    题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...

  2. hdu 4432 Sum of divisors(十进制转其他进制)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...

  3. HDU 4278 Faulty Odometer 8进制转10进制

    Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  4. HDU 1335 Basically Speaking(进制转换)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...

  5. HDU 2097 sky数 (进制转化)

    传送门: Sky数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. 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, ...

  7. HDU 2100 Lovekey (26进制大数、字符串)

    Lovekey Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  8. hdu 2097 sky数(进制转换)

    Sky数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. hdu 4278 Faulty Odometer(进制转换)

    十进制转八进制的变形: #include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF& ...

随机推荐

  1. why slow thinking wins

    今天Hacker News上的一篇文章<为什么想得慢的人能赢>引起了广泛的讨论. 网友Scott Burson在文章后评论说:"之前,我雇佣了一位TopCoder冠军,原本预计他 ...

  2. 使用Ubuntu 新建vpn过程

    1.更新软件源      sudo apt-get update   2.安装pip    sudo apt-get install python-pip   3.安装shadowsocks    s ...

  3. 菜鸟日记之 java中的集合框架

    java中的集合框架图 如图所示:java中的集合分为两种Collection和Map两种接口 可分为Collection是单列集合和Map的双列集合 Collection单列集合:继承了Iterat ...

  4. QT UI 如果发现布局之后,button不在父widget的中间

    如果发现布局之后,button不在父widget的中间: 调整父widget的布局参数:

  5. js 高级函数 之示例

    js 高级函数作用域安全构造函数 function Person(name, age)    {        this.name = name;        this.age = age;     ...

  6. PHP使用DES进行加密解密

    DES是一种对称加密算法,也就是通过密文和合法的密钥能够将明文还原出来,在程序开发过程中有些 接口可能需要获取原始数据,而发送的数据又比较敏感(比如用户的密码等信息),这时可以选择DES加密算法,DE ...

  7. ThinkPHP Uploadify 图片上载

    从官方网站下载的Uploadify最新版本:http://www.uploadify.com/download/ jQuery库是1.7.1版本. 下载好的Uploadify目录下面的文件有: 用到的 ...

  8. 精通 Oracle+Python,第 5 部分:存储过程、Python 编程

    调用数据库存储过程及其他感兴趣的高级 Python 编程功能. 2010 年 3 月发布 对于涉及数据库的软件开发来说,有两种主流开发方法:一种是在应用程序中(对于三层体系结构,也可以是在中间件中)实 ...

  9. python cookielib

    # HttpClient.py is written by [xqin]: https://github.com/xqin/SmartQQ-for-Raspberry-Piimport cookiel ...

  10. Netty启动分析

    基于Netty-3.2.5 先看一段Netty的服务端代码: import java.net.InetSocketAddress; import java.util.concurrent.Execut ...