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) ...
随机推荐
- 百练2755 奇妙的口袋 【深搜】or【动规】or【普通递归】or【递推】
总Time Limit: 10000ms Memory Limit: 65536kB 有一个奇妙的口袋.总的容积是40,用这个口袋能够变出一些物品,这些物品的整体积必须是40.John如今有n个 ...
- JBoss 系列九十九:Rest WebService jBPM 6 集成演示样例
概述 jBPM 6 提供 Rest API 供第三方应用整合使用 jBPM 6,本文演示假设通过 Rest API: 启动流程 获取流程实例信息 启动 User Task 完毕 User Task j ...
- Java Numeric Formatting--reference
I can think of numerous times when I have seen others write unnecessary Java code and I have written ...
- Android实现真正的ViewPager【平滑过渡】+【循环滚动】!!!顺带还有【末页跳转】。
实现真正的ViewPager[平滑过渡]+[循环滚动]!!!顺带还有[末页跳转]. 首先呢, 我要对网上常见的3种ViewPager的循环滚动方法做个概述.急需看真正实现方法的同志请选择性忽略下面这一 ...
- 把数据库中的null作为条件查询应该用is
如select * from mbXX where tuijian is null 而不是select * from mbXX where tuijian=null
- 3.RxJava详解
一.RxJava 到底是什么 异步(取代AsyncTask/Handler/XXX/...?) 二.RxJava 好在哪 简洁(逻辑的简洁,.一步一走) 举例: 题目:将文件夹中的图片都取 ...
- oracle存储过程写法。
create or replace procedure testwzm(v_gdjdm in varchar2) isv_id varchar2(10);v_xlname varchar2(100); ...
- oracle 空置排在最后显示
nulls last select * from emp order by comm select * from emp order by comm desc select * from emp or ...
- 配置CAS错误No Certificate file specified or invalid file format
配置tomcat证书 keystore文件后启动一直报错:(tomcat版本:apache-tomcat-6.0.43) tomcat配置: <Connector port="8443 ...
- The Primo ScholarRank Technology: Bringing the Most Relevant Results to the Top of the List
By Tamar Sadeh, Director of Marketing In today’s world, users’ expectations for a quick and easy sea ...