三个小函数

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. C#一些小技巧(二)

    教你们怎么改配色方案,因为本人智障了很久,每次想改颜色的时候都会看到一大圈的选项,难以琢磨,但是智障了那么久终于被我找到了所有的关联. 首先,要告诉你们的是,其实C#里面要改的东西只有那么几个,但是注 ...

  2. jquery validation插件

    jQuery Validate验证框架详解 jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导 ...

  3. [转] js call

    call 方法  转自: http://www.cnblogs.com/sweting/archive/2009/12/21/1629204.html调用一个对象的一个方法,以另一个对象替换当前对象. ...

  4. php基础知识【函数】(1)数组array

    一.排序 1.sort -- 从最低到最高排序,删除原有的键名,赋予新的键名[字母比数字高] 2.rsort -- 逆向排序(最高到最低),删除原有的键名,赋予新的键名[字母比数字高] 3.asort ...

  5. 如何在win7上面安装python的包

    最近在win7上面搞python,然后写的一些代码涉及到了对Excel的读写.所以需要用到包xlrd xlwt  xlutils. 但问题是这些包import后显示的是找不到.错误提示是:Import ...

  6. 配置安装theano环境(非GPU版)

    终于成功配置了theano环境,但由于本机没有gpu,所以配置的是非gpu版本的theano,下面将具体过程进行描述(安装成功后,有时对python的各种库进行更新时,可能会导致某个模块无法调用其他被 ...

  7. ShareSDK(iOS版)开发实践:自定义授权视图和分享视图导航栏

    最近很多人问ShareSDK的授权视图和分享视图的导航栏样式与应用风格不一致,能否修改导航栏的样式?那么这里我就2.6.1版本进行说明(还在使用1.x版本的朋友建议升级到2.x版本,在新版本中可定制的 ...

  8. Codeforces Round #204 (Div. 2): B

    很简单的一个题: 只需要将他们排一下序,然后判断一下就可以了! 代码: #include<cstdio> #include<algorithm> #define maxn 10 ...

  9. ZooKeeper系列之八:ZooKeeper的简单操作

    http://blog.csdn.net/shenlan211314/article/details/6187035 1 )使用 ls 命令来查看当前 ZooKeeper 中所包含的内容: [zk: ...

  10. Android 文件上传 使用AsyncHttpClient开源框架

    public void upload(View view) { AsyncHttpClient client = new AsyncHttpClient(); RequestParams reques ...