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. windows下, nginx 提示错误 "No input file specified"

    https://blog.csdn.net/m_nanle_xiaobudiu/article/details/80386035

  2. [TypeStyle] Load raw CSS in TypeStyle

    TypeStyle tries to be an all in one CSS in JS management solution so you can always fall back to raw ...

  3. JAVA中try-catch异常逃逸

    有时候一些小的细节,确实比较纠结,对于try-catch-finally代码块中代码依次执行,当try中有exception抛出时,将会有catch拦截并执行,如果没有catch区块,那么except ...

  4. hdu 2577 How to Type(DP)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. [Vue] Preload Data using Promises with Vue.js and Nuxt.js

    Nuxt.js allows you to return a Promise from your data function so that you can asynchronously resolv ...

  6. css hover控制其他元素

    <html> <body> <style> #a:hover {color : #FFFF00;} #a:hover > #b:first-child{col ...

  7. ios开发处理服务器返回的时间字符串

    #import <Foundation/Foundation.h> void other(); void string2date(); int main(int argc, const c ...

  8. QT代理Delegates使用实例(三种代理控件)

    效果如下,在表格的单元格中插入控件,用Delegates方式实现 源代码如下: main.cpp文件 #include <QApplication>#include <QStanda ...

  9. JS类型转换规则详解

    JS类型转换规则详解 一.总结 一句话总结:JS强制类型转换中的类型名强制类型转换和其它语言不同,是类型类的构造方法,Number(mix) 一句话总结(JS类型本质):因为js是弱类型语言,所以它相 ...

  10. epoll 和select

    epoll 水平触发和边缘触发的区别 EPOLLLT——水平触发EPOLLET——边缘触发 epoll有EPOLLLT和EPOLLET两种触发模式,LT是默认的模式,ET是“高速”模式.LT模式下,只 ...