Sum of divisors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4318    Accepted Submission(s): 1382

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.
 
Source
 

题目:看hint都能看懂啥意思吧。就是去找因数。挺简单~



AC代码:



#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std; int bit[100];
int cnt; void change(int n,int base)
{
cnt=0;
while(n)
{
bit[cnt++]=n%base;
n/=base;
}
}
int main()
{
int n, m;
while(scanf("%d %d", &n, &m)!=EOF)
{
int sum=0;
int t=(int)sqrt(n*1.0);
for(int i = 1; i <= t; i++)
{
if(n%i == 0)
{
int tmp = i;
while(tmp)
{
sum += ((tmp%m)*(tmp%m));
tmp /= m;
}
tmp = n/i;
if(tmp == i)continue;
while(tmp)
{
sum += ((tmp%m) * (tmp%m));
tmp /= m;
}
}
}
change(sum, m);
for(int i = cnt-1; i >= 0; i--)
{
if(bit[i] > 9) printf("%c", bit[i]-10+'A');
else printf("%d", bit[i]);
}
putchar(10);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )的更多相关文章

  1. HDU 4436 str2int(后缀自动机)(2012 Asia Tianjin Regional Contest)

    Problem Description In this problem, you are given several strings that contain only digits from '0' ...

  2. HDU 4441 Queue Sequence(优先队列+Treap树)(2012 Asia Tianjin Regional Contest)

    Problem Description There's a queue obeying the first in first out rule. Each time you can either pu ...

  3. HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)

    Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...

  4. HDU 4431 Mahjong(枚举+模拟)(2012 Asia Tianjin Regional Contest)

    Problem Description Japanese Mahjong is a four-player game. The game needs four people to sit around ...

  5. HDU 4467 Graph(图论+暴力)(2012 Asia Chengdu Regional Contest)

    Description P. T. Tigris is a student currently studying graph theory. One day, when he was studying ...

  6. HDU 4468 Spy(KMP+贪心)(2012 Asia Chengdu Regional Contest)

    Description “Be subtle! Be subtle! And use your spies for every kind of business. ”― Sun Tzu“A spy w ...

  7. HDU 3726 Graph and Queries(平衡二叉树)(2010 Asia Tianjin Regional Contest)

    Description You are given an undirected graph with N vertexes and M edges. Every vertex in this grap ...

  8. HDU 3696 Farm Game(拓扑+DP)(2010 Asia Fuzhou Regional Contest)

    Description “Farm Game” is one of the most popular games in online community. In the community each ...

  9. HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP

    意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...

随机推荐

  1. Log Explorer 使用说明(原创)

    关于Log Explorer (我抄的) 介绍Log Explorer主要用于对MSSQLServer的事物分析和数据恢复.你可以浏览日志.导出数据.恢复被修改或者删除的数据(包括执行过update, ...

  2. 【AtCoder ABC 075 B】Minesweeper

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟,把#换成1 八个方向加一下就好. [代码] #include <bits/stdc++.h> using name ...

  3. Internet连接共享只能上qq不能打开网页的问题解决

    作者:朱金灿 来源:http://blog.csdn.net/clever101 之前我写过一篇<Windows共享上网的做法>,在设置共享网络时是有一个家庭网络连接的选项的,如下图: 但 ...

  4. or小计

    1.使用or的时候,必须养成两边添加括号,否则结果完全不一样. 2.or条件如果复杂的情况下,可以适当考虑union all改写.

  5. 8、linux下输入子系统

    input_sync(button_dev);    /*通知接收者,一个报告发送完毕*/ 参考:http://www.51hei.com/bbs/dpj-27652-1.html  很详细说明 in ...

  6. Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏

    在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...

  7. [Now] Update an application hosted with Zeit’s Now

    Because now deploys are immutable, you can’t push changes to a running instance - you just push a ne ...

  8. ios开发runtime学习五:KVC以及KVO,利用runtime实现字典转模型

    一:KVC和KVO的学习 #import "StatusItem.h" /* 1:总结:KVC赋值:1:setValuesForKeysWithDictionary实现原理:遍历字 ...

  9. 用户之间imp的问题

    今天同事说申请了一个从生产导出的dump文件,须要导入測试库进行測试. 之前做的基本都是本库导出,本库导入的操作,比如:imp test/***@test tables=tbl_fuel file=H ...

  10. 妈蛋:kinMaxShow轮播图异常,WebUploader图片上传坑爹,图片被压缩了

    今天晚上在改造轮播图. 原来的代码是这样的: <div> <img src="${static}/image/index/banner/`.jpg" /> ...