HDU4432 Sum of Divisors
涉及知识点:
1. 进制转换。
2. 找因子时注意可以降低复杂度。
Sum of divisors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4837 Accepted Submission(s): 1589
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.
30 5
112
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.
Statistic | Submit | Discuss | Note
#include<stdio.h>
#include<math.h> int Out[64]; int main() {
int n, m;
while(~scanf("%d%d", &n, &m)) {
int sum = 0;
int limit = (int)sqrt(n); // 当i是因子时 n/i通常也是因子 可以将复杂度将为O(logn)。
for(int i = 1; i <= limit; i++) {
if(n % i == 0) {
int t;
t = i;
while(t) {
sum += (t % m)*(t % m);
t /= m;
}
if(i * i != n) { //避免重复计算。
t = n/i;
while(t) {
sum += (t % m) * (t % m);
t /= m;
}
}
}
}
int i = 0;
while(sum) {
Out[i++] = sum % m;
sum /= m;
}
for(int j = i - 1; j >= 0; j--) {
if(Out[j] > 9) {
printf("%c", Out[j] - 10 + 'A');
} else printf("%d", Out[j]);
}
puts("");
}
return 0;
}
HDU4432 Sum of Divisors的更多相关文章
- hdu4432 Sum of divisors(数论)
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- zoj 2286 Sum of Divisors
// f(n)表示 n的约数和 不包括自己// 给你一个m 求1 到 100万里面 f(n)<=m 的个数// 那么首先要用筛选求出所有出 f(n)// 然后就好办了 // 写好后 看见别人好快 ...
- hdu 4432 Sum of divisors(十进制转其他进制)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...
- ZOJ2286 Sum of Divisors 筛选式打表
我想我是和Segmentation Fault有仇,我一直以为是空间开大的问题,然后一直减少空间,还是SF,谁让n没有给范围了,qwq. 教训:以后注意输入范围和开的空间大小. #include< ...
- HDU 4432 Sum of divisors (水题,进制转换)
题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...
- HDU 4432 Sum of divisors (进制模拟)
三个小函数 getdiv(); 求因子 getsum(); 求平方和 change(); 转换成该进制 #include <cstdio> #include ...
- ZOJ 2562 More Divisors(高合成数)
ZOJ 2562 More Divisors(高合成数) ACM 题目地址:ZOJ 2562 More Divisors 题意: 求小于n的最大的高合成数,高合成数指一类整数,不论什么比它小的自然数 ...
- hdu-4432-Sum of divisors
/* Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- lvs keepalived 安装配置详解【转】
lvs keepalived 安装配置详解 张映 发表于 2012-06-20 分类目录: 服务器相关 前段时间看了一篇文章,lvs做负载均衡根F5差不多,说实话不怎么相信,因为F5没玩过,也无法比较 ...
- App发布AppStore【苹果开发者中心需要做的事】
请准许我的这句抱怨,也说明发布app到AppStore理清这些东西的重要性:起初打包出现各种 ApplicationVerificationFailed,不是这里没有搞对就是那个证书没有搞对,整个人签 ...
- Can a Tomcat docBase span multiple folders?--转
Question: I apologize if this is a poor question, but I'm using Windows and looking to see if there' ...
- linux下常用基本命令操作
#fdisk -l 查看硬盘信息 cat /proc/cpuinfo 查看CPU信息 free -m 查看内存信息 ethtool eth0 查看网卡信息 df -h 查看硬盘各分区可用空间大小 ca ...
- 【网络流#4】UVA 753 最大流
最近开始刷网络流的题目了,先从紫书上的开始,这道题是P374上的,嘛,总之这道题最终还是参考了一下紫书. 中间是用了STL中map将字符串映射成编号,使用编号总比是用字符串简单的多. 超级源点S与各个 ...
- SpringMVC04controller中定义多个方法
public class MyController extends MultiActionController { // 新增 方法修饰符要是public public ModelAndView ad ...
- C#进程启动实例
1.调用widnows资源管理器打开文件夹 private void OpenFolder(string folder) { System.Diagnostics.Process.Start(&quo ...
- iOS判断当前控制器是否正在显示
+(BOOL)isCurrentViewControllerVisible:(UIViewController *)viewController { return (viewController.is ...
- prototype constructor __proto__
constructor, prototype, __proto__ 详解
- jquery获取浏览器高度、宽度和滚动条高度(来自网络)
Jquery代码: alert($(window).height()); //浏览器时下窗口可视区域高度 alert($(document).height()); //浏览器时下窗口文档的高度 ale ...