/*
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1996 Accepted Submission(s): 679 Problem Description
mmm is learning division, she's so proud of herself that she can figure out the sum of all the divisors of numbers no larger than 100 within one day!
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. Input
Multiple test cases, each test cases is one line with two integers.
n and m.(n, m would be given in 10-based)
1≤n≤109
2≤m≤16
There are less then 10 test cases. Output
Output the answer base m. Sample Input
10 2
30 5 Sample Output
110
112
Hint 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 <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 26000
int a[maxn];
int sum;
int k,i,j,tmp;
char b[maxn];
void yinzi(int n)
{
k=;
for(i=; i*i<=n; i++)
{
if(n%i==)
{
a[k++]=i;
if(i!=n/i)
a[k++]=n/i;
}
}
}
void change(int m)
{
sum=;
for(i=; i<k; i++)
{
while(a[i])
{
tmp=a[i]%m;
sum+=tmp*tmp;
a[i]=a[i]/m;
}
}
}
void rechange(int x,int m)
{
j=;
stack<char> st;
while(x)
{
tmp=x%m;
if(tmp>=)
st.push('A'+tmp-);
//b[j++]='A'+tmp-10;
else
st.push(tmp+'');
// b[j++]=tmp+'0';
x=x/m;
}
while(!st.empty())
{
cout<<st.top();
st.pop();
}
/*if(x)
{
rechange(x/m,m);
tmp=x%m;
if(tmp>=10)
printf("%c",'A'+tmp-10);
else
printf("%d",tmp);
}*/
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{ yinzi(n);
change(m);
rechange(sum,m);
//cout<<" j= "<<j<<endl;
/*for(i=j-1;i>=0;i--)
{
//printf("%c",b[i]);
cout<<b[i];
}*/
printf("\n");
}
return ;
}
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
using namespace std;
int cal;
void Base(int n,int m){
if(n)
{
Base(n/m,m);
cal+=(n%m)*(n%m);
}
}
void out(int n,int m){
if(n){
out(n/m,m);
if(n%m>)
printf("%c",'A'+(n%m)-);
else printf("%d",n%m);
}
}
int main(){ int n,m;
int i,k,sum;
while(scanf("%d %d",&n,&m)!=EOF){
//k=sqrt(n+1.0);
sum=;
for(i=;i*i<n;i++)
{
if(n%i==){
cal=;
Base(i,m);
sum+=cal;
cal=;
Base(n/i,m);
sum+=cal;
}
}
if(i*i==n){
cal=;
Base(i,m);
sum+=cal;
}
out(sum,m);
printf("\n");
}
return ;
}
/*错误代码,求解*/
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 260000
int a[maxn];
int sum;
int k,i,tmp;
char b[maxn];
void yinzi(int n)
{
k=;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
a[k++]=i;
if(i!=n/i)
a[k++]=n/i;
}
}
}
void change(int m)
{
sum=;
for(i=;i<k;i++)
{
while(a[i])
{
tmp=a[i]%m;
sum+=tmp*tmp;
a[i]=a[i]/m;
}
}
} int main()
{
int n,m,x,j;
while(~scanf("%d%d",&n,&m))
{
yinzi(n);
change(m);
// rechange(sum,m);
x=sum;
j=;
while(x)
{
tmp=x%m;
if(tmp>=)
b[j++]=tmp-+'A';
else
b[j++]=tmp+'';
x=x/m;
}
for(i=j-;i>=;i--)
{
printf("%c",b[i]);
}
printf("\n");
}
return ;
}

hdu-4432-Sum of divisors的更多相关文章

  1. hdu 4432 Sum of divisors(十进制转其他进制)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...

  2. HDU 4432 Sum of divisors (水题,进制转换)

    题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...

  3. HDU 4432 Sum of divisors (进制模拟)

    三个小函数 getdiv();        求因子 getsum();     求平方和 change();     转换成该进制 #include <cstdio> #include ...

  4. hdu4432 Sum of divisors(数论)

    Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU4432 Sum of Divisors

    涉及知识点: 1. 进制转换. 2. 找因子时注意可以降低复杂度. Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  6. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  7. hdu 1258 Sum It Up(dfs+去重)

    题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...

  8. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  9. HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)

    C - 最大连续子序列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  10. HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)

    Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status  ...

随机推荐

  1. 菜单项onCreateOptionsMenu()和onOptionsItemSelected()的使用

    Java源文件 package com.example.macname.myapplication; import android.support.v7.app.AppCompatActivity; ...

  2. Rails 5 Test Prescriptions 第10章 Unit_Testing JavaScript(新工具,learn曲线太陡峭,pass)

    对Js的单元测试是一个大的题目.作者认为Ruby的相关测试工具比Js的测试工具更灵活 大多数Js代码最终是关于响应用户的行为和改变DOM中的元素 没有什么javascript的知识点.前两节用了几个新 ...

  3. thinkphp3.2验证码在服务器上显示不出来

    ThinPHP3.2 验证码 在本地服务器访问可以显示,上传到服务器就不能访问了 /**** * 验证码 */ function code() { $config=array( 'fontSize'= ...

  4. 【转】ubuntu下修改文件夹权限

    常用方法如下: sudo chmod 600 ××× (只有所有者有读和写的权限)sudo chmod 644 ××× (所有者有读和写的权限,组用户只有读的权限)sudo chmod 700 ××× ...

  5. java读取PHP接口数据的实现方法(四)

    PHP文件: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3 ...

  6. 解决PCI Geomatica 无法卸载的问题

    之前安装过PCI Geomatica 2016,非正常卸载,应该有一定残留,但我已经尽可能将注册表中包含PCI.Geomatica.Geomatics等关键字的条目删除干净了. 在重新安装新版本201 ...

  7. Java解析Json数据的两种方式

    JSON数据解析的有点在于他的体积小,在网络上传输的时候可以更省流量,所以使用越来越广泛,下面介绍使用JsonObject和JsonArray的两种方式解析Json数据. 使用以上两种方式解析json ...

  8. 线程互斥,mutex

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  9. 12.21 Gson的常用用法 功能介绍 特点

    使用谷歌GSON常用语法: 功能:映射Java Object与json格式的数据 1.通过Annotation注解来声明 2.支持自定义属性名称 3.支持包含或排除属性 4.支持自定义接口自己完成解析 ...

  10. 20181009-2 选题 Scrum立会报告+燃尽图(01)

    Scrum立会报告+燃尽图(01)选题 此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2190 一.小组介绍 组长:刘莹莹 ...