HDU 4432 Sum of divisors (进制转换模板)
2016-07-26 20:42
387 查看
代码:
#include<string.h> #include<stdio.h> #include<math.h> using namespace std; int n,m,an; int change(int n,int m) { int i,ui=0; while(n) { i=n; ui=ui+(i%m)*(i%m); n=n/m; } return ui; } int main() { while(~scanf("%d%d",&n,&m)) { int t=sqrt(n),an=0; for(int i=1;i<=t;i++) { if(n%i==0) { an=an+change(i,m); if(n/i!=i) { an=an+change(n/i,m); } } } char a[102]; int j=0; //printf("%d\n",an); while(an) { a[j++]=an%m>9?(an%m)-10+'A':an%m+'0'; an=an/m; } for(int i=j-1;i>=0;i--) { printf("%c",a[i]); } printf("\n"); } }
Sum of divisors
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
4432
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≤10 9
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.
相关文章推荐
- signal 信号捕捉 和模拟实现 my_sleep
- java工具类开发之json工具类JsonUtils和写数据回页面工具类ResponseUtils
- socket编程用线程实现TCP协议通信
- 公路乘车(完全背包)
- git原理-文件是如何存储的
- hdu5754 Life Winner Bo(博弈)
- 【HD 2141】Can you find it?
- Android Studio,“Failed to sync Gradle project 'xxxx' ”的解决
- 【SHOI2001】洛谷2530 化工厂装箱员
- 隐藏标题栏
- 【杭电2141】Can you find it?
- bat批处理设置Java JDK系统环境变量文件
- paper 99:CV界的明星人物经典介绍
- HeadFirst设计模式读书笔记——简单工厂模式
- Volley的使用(三):Volley与Activity的联动 + Volley的二次封装
- ubuntu 环境变量设置
- express,使用session进行身份认证
- Java多线程面试题
- line-height 和 vertical-align 行高与行对齐精解 (图文)
- HDU 5750 Dertouzos (数论)