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) ...
随机推荐
- WebRTC源码分析:音频模块结构分析
一.概要介绍WebRTC的音频处理流程,见下图: webRTC将音频会话抽象为一个通道Channel,譬如A与B进行音频通话,则A需要建立一个Channel与B进行音频数据传输.上图中有三个Chann ...
- Intellij IDEA 杂记
添加JUnit File > Settings > Plugins > Browse repositories > 搜索junit ,安装JunitGenerator V2 重 ...
- Python基础 列表
---***---传送门---***--- 文档解释 def append(self, p_object): """ L.append(object) -> Non ...
- JS鼠标滑轮事件的写法和按键的事件
在body注册一下滑轮事件 <body onload="win_onload();"></body> 然后JS代码如下: function win_onlo ...
- 关于dll的路径问题
最近在做一个sdk二次开发的项目,具体是将一个C++开发的SDk用C#将它的API接口全部封装一遍,然后再做一个demo就好了 好不容易封装完了,在使用的时候出了问题.原来SDK中的dll老是加载不到 ...
- 传参方式由url携带改为post提交
参考:http://www.cnblogs.com/logon/p/3218834.html 我们这里使用了iframe嵌套form表单POST提交,很简单,却能满足get|post等任何复杂情况的要 ...
- 通过javascript完成分页查询功能
主要思路: 实现分页查询的关键是设置一个页面的最大数据行数和开始行号,代码如下: 最大行数我们设置为常量,不必纠结于他,所以关键就是如何把起始行号设置为变量,让他随着我们点击[上一页]或[下一页]而改 ...
- javaScript-原型、继承-01
为什么会有原型这个概念: 1.优雅的创建对象: 2.继承: 先看js 之前创建对象的方式存在的问题: 创建对象方式 1.字面量 var obj={name:"join",age:1 ...
- nginx 配置虚拟主机(支持php)
配置步骤: 1.在nginx安装目录下,找到nginx.conf所在文件夹,新建vhost文件夹 2.在nginx.conf http{} 末端加入 include vhost/*.conf; 3.进 ...
- eclipse提示servlet不存在 的解决办法
在以前的版本中,Tomcat的common/lib目录下有一个名为servlet-api.jar的包,把它拷贝至你的java安装目录下jre/lib/ext下就可以了. 如果是:tomcat6就在To ...