/*
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. 流行得前端构建工具比较,以及gulp配置

    前端现在三足鼎立的构建工具(不算比较老的ant,yeoman),非fis,grunt,gulp莫属了. fis用起来最简单,我打算自己得项目中使用一下fis. 先说一下gulp安装吧. 第一步:安装n ...

  2. 一定要用Windows自带的记事本编辑 applicationHost.config

    访问IIS时,发生了一个 HipIISEngineStub.dll不能读取的问题.(Windows Event可以确认). 很容易在网上找到了对策, http://chrisfleischhacker ...

  3. 路由跟踪tracert

    Tracert命令 如果我们要测试某一个IP都经过哪些路由,用trcert命令即可,这是dos下的一个基本网络命令,具体使用方法: 1,在windows系统下,打开 运行 :输入 cmd :在弹出的d ...

  4. codefroce385E矩阵快速幂

    状态变化  (x,y,dx,dy,i) 表示i时刻熊站在(x,y)处速度向量(dx,dy)下一个状态是 ( 2x+y+dx+i , x+2y+dy+i , x+y+dx , x+y+dy , i+1 ...

  5. Leetcode 34

    //二分查找后,向两边扩展,二分错了两次,现在是对的.//还有就是vector可以用{}直接赋值很棒 class Solution { public: vector<int> search ...

  6. linux hosts.equiv设置解析

    hosts.equiv文件的用途与格式 一. hosts.equiv 文件的用途 /etc/hosts.equiv 和 $HOME/.rhosts 定义了哪些计算机和用户可以不用提供口令就在本地计算机 ...

  7. Fragment在Activity中跳转,实现类似新闻标题跳转新闻内容功能

    1.准备的工作,新闻数据类,新闻数据适配器,适配器的布局: News.java package com.example.zps.fourfragmentbestpractice; /** * Crea ...

  8. 99%的人都理解错了HTTP中GET与POST的区别(转自知乎)

    作者:Larry链接:https://zhuanlan.zhihu.com/p/22536382来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. GET和POST是HTT ...

  9. linux centos 虚拟机新安装后没有网络

    ping的时候出现 name or service not known的时候 可以 修改/etc/sysconfig/network-scripts/ifcfg-ens33 文件 vi ifcfg-e ...

  10. 归并排序算法-Java实现

    简介: 归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的.然后再把有序子序列合并为整体有序 基本思想: 将一个无序数组,利用 ...