hdu 4432 因子

来源:互联网 发布:js跨域上传文件 编辑:程序博客网 时间:2024/04/25 13:50

Sum of divisors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5052    Accepted Submission(s): 1673


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 230 5
 

Sample Output
110112
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.
 

Source
2012 Asia Tianjin Regional Contest




区域赛水题


取因子

这里用sqrt (n)    同时取两个因子,不需要标记

      若一个是  i   另外一个就是   n / i   ,因为是开根号就不用标记,不用怕之前已经被用过了





#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;long long n;int m;int a[100000000];long long pos;int main(){    //freopen("in.txt","r",stdin);    while(scanf("%I64d%d",&n,&m)!=EOF)    {        long long ans=0;        long long number=sqrt(n*1.0);        long long x,i;        for(i=1;i<=number;i++){            if(n%i==0){                x=i;                while(x)                {                    int t=x%m;                    ans+=t*t;                    x=x/m;                }                x=n/i;                while(x)                {                    int t=x%m;                    ans+=t*t;                    x=x/m;                }            }        }        if(n==1)            ans=1;        pos=0;        while(ans)        {            a[pos++]=ans%m;            ans/=m;        }        pos--;        for(long long i=pos;i>=0;i--){            if(a[i]>9)                printf("%c",a[i]+'A'-10);            else                printf("%d",a[i]);        }        puts("");    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 因为飞机延误耽误行程怎么办 伤了朋友的心怎么办 羊蹄被绳子缠肿了怎么办 新老师教的不好怎么办 跟老公三观不合怎么办 突然有社保补扣怎么办 街头篮球篮板反应慢怎么办 换水了龙鱼顶缸怎么办 压着眼睛睡觉醒来模糊怎么办 天热眼睛有眼屎怎么办 眼睛里膜起来了怎么办 眼睛一边大一边小怎么办 眼白膜鼓起来了怎么办 主持问答环节没人提问怎么办 转学原学校不给怎么办 村长借东西不还怎么办 村长不上报建房申请怎么办 村长不上报建房手续申请怎么办 村长不给村民盖章怎么办? 找村干部办事难怎么办 洪洞县村长不给我盖章怎么办 睾丸穿刺取精只配到6个胚胎怎么办 孩子一只耳朵听不到声音怎么办 孕早期孕囊生长慢怎么办 试管2次不着床怎么办? pescm球员年龄大了怎么办 实况足球俱乐部经理球员老了怎么办 你不是我的菜怎么办 苹果平板电脑耳机有回音怎么办 obs直播有电流音怎么办 语音里网吧很吵怎么办 电脑k歌有延迟怎么办 想开个跆拳道馆怎么办营业执照? 壶嘴拐弯处漏水怎么办 裂纹茶壶嘴坏了怎么办 小孩刚上学怕她上火怎么办 在幼儿园小朋友不愿叠衣服怎么办 孩子在家听话幼儿园不听话怎么办 变魔术时观众说看过这个怎么办 孕妇8个月摔跤了怎么办 孩子吃了残奶怎么办