Sum of divisors
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.
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.
#include <stdio.h>
int change(int number,int m);
int main(){
int n;
int m;
int i;
int j;
int length;
int sum;
int temp;
char s[];
while(scanf("%d%d",&n,&m)!=EOF){
sum=;
for(i=;i*i<=n;i++){ //这里i*i<=n,如果i从1到n则超时
if(n%i==){
temp=change(i,m);
sum+=temp;
if(i!=n/i){ //如果i和n/i相等则算一次
temp=change(n/i,m);
sum+=temp;
}
}
}
i=;
while(sum){
temp=sum%m;
if(temp<=)
s[i]=temp+'';
else if(temp==)
s[i]='A';
else if(temp==)
s[i]='B';
else if(temp==)
s[i]='C';
else if(temp==)
s[i]='D';
else if(temp==)
s[i]='E';
else if(temp==)
s[i]='F';
i++;
sum/=m;
}
length=i;
for(i=length-;i>=;i--)
printf("%c",s[i]);
printf("\n");
}
return ;
}
int change(int number,int m){
int temp;
int result;
result=;
while(number){
temp=number%m;
result+=temp*temp;
number/=m;
}
return result;
}
Sum of divisors的更多相关文章
- hdu4432 Sum of divisors(数论)
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU4432 Sum of Divisors
涉及知识点: 1. 进制转换. 2. 找因子时注意可以降低复杂度. Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- 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) ...
随机推荐
- js实现异步循环
@(编程) 问题 实现异步循环时,你可能会遇到问题. 让我们试着写一个异步方法,每秒打印一次循环的索引值. for(var i = 0; i < 5; i++) { setTimeout(fun ...
- HDU 4497 GCD and LCM (数学,质数分解)
题意:给定G,L,分别是三个数最大公因数和最小公倍数,问你能找出多少对. 析:数学题,当时就想错了,就没找出规律,思路是这样的. 首先G和L有公因数,就是G,所以就可以用L除以G,然后只要找从1-(n ...
- CodeForces 702B Powers of Two (暴力,优化)
题意:给定 n 个数,问你从有多少下标 i < j,并且 ai + aj 是2的倍数. 析:方法一: 从输入开始暴力,因为 i < j 和 i > j 是一样,所以可以从前面就开始查 ...
- F5 负载均衡 相关资源
F5负载均衡之检查命令的说明http://net.zdnet.com.cn/network_security_zone/2010/0505/1730942.shtml F5培训http://wenku ...
- C:函数指针、回调函数
函数指针 是一个指针,指向函数的指针,指针存放的都是地址,所以函数指针存放的是函数的地址.数组名就是数组的首地址,函数名就是函数的首地址.与数组类似. 代码demo int (*p) (int ,in ...
- CloudStack4.2 二级镜像存储测试
//添加二级存储{ "addimagestoreresponse": { "imagestore": { "id": "2dda4 ...
- Oracle和plsql developer编码设置
在使用pl/sql developer时,查询出来中文字段显示乱码,因为数据库的编号格式和pl /sql developer的编码格式不统一造成的. 一.查看和修改oracle数据库字符集 selec ...
- 安装配置tomcat环境
安装配置tomcat环境 #所需要软件包 apache-tomcat-7.0.65.tar.gz jdk-7u80-linux-x64.gz #建立 个专用账户 usradd tomcat ...
- URAL 1233 - Amusing Numbers
首先计算出k至少为第几位,如果m小于这个数,那么输出0 还有一种情况, 就是10的i次方的这种情况,如果i+1等于m,那么直接输出k,否则输出0 其他的情况,就是二分,然后判断计算其插入到k之前的数的 ...
- CSS选择器 使用小结
==> .x-boundlist-floating[style$="px;"] .x-boundlist-item 元素中含有Style属性,并且属性值以"px;& ...