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) ...
随机推荐
- 实战:mysql版本号升级
/***************************************************** mysql 5.6.19 升级到5.6.21 ********************** ...
- .NET注册页面代码
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- 命名空间引用问题 包括找不到ConfigurationManager 这个类
因为SqlConnection类是属于 System.Data.SqlClient命名空间下的, 所以命名空间引用的时候需要加上 System.Data.SqlClient,代码如下: ...
- Android中完全退出当前应用系统
一.将统一管理Activity的类ActivityManager复制到工程里面. package com.jsmtr.www.Helper; import java.util.LinkedList; ...
- MySQL 5.6.19编译安装
1.创建mysql安装目录.mysql用户 [root@serv19 ~]# mkdir -p /u01/mysql/data [root@serv19 ~]# groupadd mysql [roo ...
- Activity 状态的保存和恢复
Activity状态保存的两种情况 一.Activity状态保持概念 保存Activity的状态是非常重要的,例如我们在玩一个游戏的时候,突然来了一个电话,这个时候在接听完电话之后我们返回到游戏中,这 ...
- poj 1850 1019 (简单位数dp)
#include<iostream> #include<cstdio> #include<cstring> using namespace std; ][],l,a ...
- jQuery回到顶部
jquery回到顶部 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=& ...
- Error: theForm.submit is not a function !!
theForm.submit is not a function 调试了半天,才发现范了低级错误. 页面中有一个按钮ID 是 submit 而引发的错误. 引出的问题是页面上的元素命名范围不能是 wi ...
- CSS3 边框
说明:CSS3完全向后兼容,因此不必改变现有的设计.浏览器通常支持CSS2 CSS3模块 CSS3被划分为模块: 选择器 框模型 背景和边框 文本效果 2D/3D 转换 动画 多列布局 用户界面 CS ...