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. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  2. JQuery点击收起,点击展开以及部分非空小验证

    <tr> <td nowrap align="right" width="18%"> 解决方案: </td> <td ...

  3. ImageSwitcher的应用

    在android的开发中很多时候都会用到图片的切换,我相信大家在安装完apk后,都会遇到弹出用户向导,介绍本版本apk的新功能,如果你用的是平板电脑或手机的话,可以左右滑动以切换视图,如果你用的是an ...

  4. iOS多线程总结

    1.不要同时开太多的线程(1~3条线程即可,不要超过5条) 2.线程概念 1> 主线程 : UI线程,显示.刷新UI界面,处理UI控件的事件 2> 子线程 : 后台线程,异步线程 3.不要 ...

  5. springAOP配置文件

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. Toast在关闭应用后还显示的解决办法

    1.我们在用Toast的用法就是:Toast.makeText(Context,CharSequence , Duration).show().但有的时候如果你在一次操作当中多次点击一个view的时候 ...

  7. Sublime Text3 激活教程

    Sublime Text3激活 在使用Sublime时会定期弹出购买提示框,避免出现购买提示,影响工作效率,我们可以使用网上的激活码,虽然有些不厚道,但是工作以后,一定选择购买正版支持一下. 打开Su ...

  8. Android中GridView的实现实例

    实现效果: activity文件代码: package com.tmacsky; import android.app.Activity; import android.os.Bundle; impo ...

  9. How to get cocoapods work on Yosemite

    查看原文:http://leancodingnow.com/how-to-get-cocoapods-work-on-yosemite/ 今天升级了Mac OS X 10.10-Yosemite以后运 ...

  10. Slony-I的删除:

    接前篇:http://www.cnblogs.com/gaojian/p/3196244.html 简单的Slony-I设置实例 如何删除slony相关的内容呢. 我再另外找一台机器,安装slony, ...