2012 天津站B題||hdu4432 進位制轉換 模擬
http://acm.hdu.edu.cn/showproblem.php?pid=4432
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.
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.
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其實就是一個模擬的問題,值得一提的是n==1要特殊考慮。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef __int64 LL;
int m;
LL n,a[555555];
int get_factor(LL n)
{
int sum=0;
memset(a,0,sizeof(a));
for(int i=1;i*i<n;i++)
if(n%i==0)
{
a[sum++]=i;
a[sum++]=n/i;
}
/*for(int i=0;i<sum;i++)
printf("%d ",a[i]);
printf("\n");*/
return sum;
}
void change(vector<int> &v,LL x)
{
// printf("====%d=====\n",x);
while(x)
{
v.push_back(x%m);
x/=m;
}
/*for(int i=0;i<v.size();i++)
printf("%d ",v[i]);
printf("\n");
*/
}
void jinzhi(LL x,int y)
{
if(x)
{
jinzhi(x/y,y);
printf("%c",x%y>9 ? x%y-10+'A':x%y+'0');
}
}
vector <int> v[555555];
int main()
{
while(~scanf("%I64d%d",&n,&m))
{
if(n==1)
{
printf("1\n");
continue;
}
for(int i=0;i<555555;i++)
v[i].clear();
int num=get_factor(n);
for(int i=0;i<num;i++)
change(v[i],a[i]);
LL sum=0;
for(int i=0;i<num;i++)
for(int j=0;j<v[i].size();j++)
sum+=v[i][j]*v[i][j];
jinzhi(sum,m);
printf("\n");
}
return 0;
}
相關文章
- PAT B1022 D進位制的A+B(進位制轉換板題,簡單模擬)
- NUMBER BASE CONVERSION(進位制轉換) 經典模擬
- Qt進位制轉換(十進位制轉十六進位制)QT
- 進位制轉換
- 基礎問題:進位制轉換
- 進位制之間的轉換之“十六進位制 轉 十進位制 轉 二進位制 方案”
- JavaScript 進位制轉換JavaScript
- 【python】進位制轉換Python
- 進位制的轉換
- 二進位制,八進位制,十進位制,十六進位制的相互轉換
- JavaScript十進位制轉換為二進位制JavaScript
- java中二進位制、八進位制、十進位制、十六進位制的轉換Java
- 二進位制,八進位制,十進位制,十六進位制之間的轉換
- 【進位制轉換】二進位制、十六進位制、十進位制、八進位制對應關係
- 進位制與二進位制及相關轉換
- 進位制轉換圖解圖解
- JAVA 二進位制,八進位制,十六進位制,十進位制間進行相互轉換Java
- 計算機基礎進位制轉換(二進位制、八進位制、十進位制、十六進位制)計算機
- 什麼是二進位制?二進位制如何轉換?
- [20190716]十進位制轉換其他進位制指令碼.txt指令碼
- 十進位制轉換任意進位制--鏈棧實現
- 計算機求解10進位制轉換任意進位制計算機
- JavaScript中的多種進位制與進位制轉換JavaScript
- 一看就懂二進位制、八進位制、十六進位制數轉換十進位制
- c++的進位制轉換C++
- 技術問 - 進位制轉換
- 進位制轉換的工具類
- JavaScript 進位制轉換 All In OneJavaScript
- Python中各進位制轉換Python
- [計算機基礎] 計算機進位制轉換:二進位制、八進位制、十進位制、十六進位制計算機
- 口算 16 進位制轉換 10 進位制,但只適合兩位的 16 進位制
- Python 十進位制轉換為二進位制 高位補零Python
- oracle_16進位制與10進位制轉換小示例Oracle
- 關於Java中進位制轉換以及位運算問題Java
- PAT-B 1022 D進位制的A+B【進位制】
- Python處理十六進位制與二進位制轉換的問題——binascii自帶庫PythonASCII
- 計算機中進位制轉換計算機
- 資料轉換-16進位制字元字元
- 遞迴函式實現十進位制正整數轉換為二進位制,八進位制,十六進位制遞迴函式