HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )
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
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.
n and m.(n, m would be given in 10-based)
1≤n≤109
2≤m≤16
There are less then 10 test cases.
10 2
30 5
110
112HintUse 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.
题目:看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 )的更多相关文章
- HDU 4436 str2int(后缀自动机)(2012 Asia Tianjin Regional Contest)
Problem Description In this problem, you are given several strings that contain only digits from '0' ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP
意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...
随机推荐
- 【AtCoder ABC 075 D】Axis-Parallel Rectangle
[链接] 我是链接,点我呀:) [题意] 让你找到一个各边和坐标轴平行的矩形.使得这个矩形包含至少K个点. 且这个矩形的面积最小. [题解] 把所有的"关键点""都找出来 ...
- PatentTips - Handling shared interrupts in bios under a virtualization technology environment
BACKGROUND This relates to the operation of software under a virtualization technology (VT) environm ...
- VS提示SurfFeatureDetector不是cv的成员函数 .
原因:没有把 opencv_nonfree243d.lib 加入lib库中. 还有两个头文件:#include <opencv2/nonfree/features2d.hpp>#inclu ...
- [TypeStyle] Use fallback values in TypeStyle for better browser support
You can increase the browser support of your CSS using fallback values and vendor prefixes. This les ...
- Access Violations 访问冲突(AVs)是Windows编程时发生的最麻烦的错误?
Access Violations<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office&qu ...
- MinGW 与MSVC的区别
Qt 中有两种方式编译,一种是MinGW ,另一种MSVC. 其中:MSVC是指微软的VC编译器 MingGW是指是Minimalist GNU on Windows的缩写.它是一个可自由使用和自由发 ...
- jquery-6 jquery属性选择器
jquery-6 jquery属性选择器 一.总结 一句话总结:jquery操作就是选择器加jquery对象的各种方法. 1.大量操作样式用什么方式? 大批量样式通过加类和减类完成 2.jquery中 ...
- todo bitnami
https://bitnami.com/stack/dokuwiki https://bitnami.com/stack/jenkins/installer
- 【74.89%】【codeforces 551A】GukiZ and Contest
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- eclipse jdt
http://www.cnblogs.com/hoojo/p/use_eclipse_ant_javac_JDT_compiler_class.html