Problem Description
mmm is learning division, she's so proud of herself that she can figure out the sum of all the divisors of numbers no larger than 100 within one day!
But her teacher said "What if I ask you to give not only the sum but the square-sums of all the divisors of numbers within hexadecimal number 100?" mmm get stuck and she's asking for your help.
Attention, because mmm has misunderstood teacher's words, you have to solve a problem that is a little bit different.
Here's the problem, given n, you are to calculate the square sums of the digits of all the divisors of n, under the base m.
 
Input
Multiple test cases, each test cases is one line with two integers.
n and m.(n, m would be given in 10-based)
1≤n≤109
2≤m≤16
There are less then 10 test cases.
 
Output
Output the answer base m.
 
Sample Input
10 2
30 5
 
Sample Output
110
112
 
Hint

Use A, B, C...... for 10, 11, 12......
Test case 1: divisors are 1, 2, 5, 10 which means 1, 10, 101, 1010 under base 2, the square sum of digits is
1^2+ (1^2 + 0^2) + (1^2 + 0^2 + 1^2) + .... = 6 = 110 under base 2.

 
 #include <stdio.h>

 int change(int number,int m);

 int main(){
int n;
int m;
int i;
int j;
int length;
int sum;
int temp;
char s[]; while(scanf("%d%d",&n,&m)!=EOF){
sum=;
for(i=;i*i<=n;i++){ //这里i*i<=n,如果i从1到n则超时
if(n%i==){
temp=change(i,m);
sum+=temp; if(i!=n/i){ //如果i和n/i相等则算一次
temp=change(n/i,m);
sum+=temp;
}
}
} i=;
while(sum){
temp=sum%m; if(temp<=)
s[i]=temp+''; else if(temp==)
s[i]='A'; else if(temp==)
s[i]='B'; else if(temp==)
s[i]='C'; else if(temp==)
s[i]='D'; else if(temp==)
s[i]='E'; else if(temp==)
s[i]='F'; i++;
sum/=m;
} length=i; for(i=length-;i>=;i--)
printf("%c",s[i]); printf("\n");
} return ;
} int change(int number,int m){
int temp;
int result; result=;
while(number){
temp=number%m;
result+=temp*temp;
number/=m;
}
return result;
}

Sum of divisors的更多相关文章

  1. hdu4432 Sum of divisors(数论)

    Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU4432 Sum of Divisors

    涉及知识点: 1. 进制转换. 2. 找因子时注意可以降低复杂度. Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  3. zoj 2286 Sum of Divisors

    // f(n)表示 n的约数和 不包括自己// 给你一个m 求1 到 100万里面 f(n)<=m 的个数// 那么首先要用筛选求出所有出 f(n)// 然后就好办了 // 写好后 看见别人好快 ...

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

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

  5. ZOJ2286 Sum of Divisors 筛选式打表

    我想我是和Segmentation Fault有仇,我一直以为是空间开大的问题,然后一直减少空间,还是SF,谁让n没有给范围了,qwq. 教训:以后注意输入范围和开的空间大小. #include< ...

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

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

  7. HDU 4432 Sum of divisors (进制模拟)

    三个小函数 getdiv();        求因子 getsum();     求平方和 change();     转换成该进制 #include <cstdio> #include ...

  8. ZOJ 2562 More Divisors(高合成数)

    ZOJ 2562 More Divisors(高合成数) ACM 题目地址:ZOJ 2562 More Divisors 题意:  求小于n的最大的高合成数,高合成数指一类整数,不论什么比它小的自然数 ...

  9. hdu-4432-Sum of divisors

    /* Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. Servlet 2.4 规范之第一篇:概览

          写在前面的话: 本系列是对<Java Servlet Specification Version 2.4>的完全翻译,力争但不保证完美表达出英文原文的思想内涵.如有疏漏之处,还 ...

  2. UVALive 3959 Rectangular Polygons (排序贪心)

    Rectangular Polygons 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/G Description In thi ...

  3. Java沙箱技术

    自从Java技术出现以来,有关Java平台的安全性及由Java技术发展所引发的新的安全性问题,引起了越来越多的关注.目前,Java已经大量应用在各个领域,研究Java的安全 性对于更好地使用Java具 ...

  4. 利用预渲染加速iOS设备的图像显示

    最近在做一个UITableView的例子,发现滚动时的性能还不错.但来回滚动时,第一次显示的图像不如再次显示的图像流畅,出现前会有稍许的停顿感.于是我猜想显示过的图像肯定是被缓存起来了,查了下文档后发 ...

  5. Add mappings to an Elasticsearch index in realtime

    Changing mapping on existing index is not an easy task. You may find the reason and possible solutio ...

  6. spring+jpg环境下,spring实现文件上传

    jsp: <form method="post" action="excel.do?method=inputExcel" enctype="mu ...

  7. 用DependanceProperty做Dynamic换Icon

    1:做Icon用Canvas还是DrawingBrush? Canvas的例子:

  8. 27.怎样在Swift中声明typedef?

    在OC中,我们经常会用typedef关键字来声明Block,例如: /** * 通用的空闭包类型,无参数,无返回值 */ typedef void (^GofVoidBlock)(void); 在Sw ...

  9. openNebula Image上传

    Rack:ruby webserver框架 https://rack.github.io/ 文件上传使用基于tempfile 库 文件上传要经历两个过程: 1.上传文件传到opennebule sun ...

  10. <meta http-equiv = "X-UA-Compatible" cotent = "IE=edge,chrome=1"/>

    <meta http-equiv = "X-UA-Compatible" cotent = "IE=edge,chrome=1"/> 制定ie调用哪 ...