zoukankan      html  css  js  c++  java
  • Sum of divisors

    Sum of divisors

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 52   Accepted Submission(s) : 14
    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≤10[sup]9[/sup] 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.[/hint]
     
    Source
    2012 Asia Tianjin Regional Contest
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 int main()
     4 {
     5     int j,i,m,n,sum,Len,k,a;
     6     char NUM[1000];
     7     while(scanf("%d %d",&m,&n)!=EOF)
     8     {
     9         for(i=1,sum=0;i*i<=m;i++)
    10         {
    11             if(m%i==0)
    12             {
    13                 itoa(i,NUM,n);
    14                 Len=strlen(NUM);
    15                 for(j=0;j<Len;j++)
    16                 {if(NUM[j]<='f'&&NUM[j]>='a') a=NUM[j]-'a'+10;
    17                     else a=NUM[j]-'0';
    18                     sum+=a*a;}
    19                 if(i==m/i)continue;
    20                 itoa(m/i,NUM,n);
    21                 Len=strlen(NUM);
    22                 for(j=0;j<Len;j++)
    23                 {if(NUM[j]<='f'&&NUM[j]>='a') a=NUM[j]-'a'+10;
    24                     else a=NUM[j]-'0';
    25                     sum+=a*a;}
    26             }
    27 
    28         }
    29         itoa(sum,NUM,n);
    30         Len=strlen(NUM);
    31         for(i=0;i<Len;i++)
    32          {
    33             if(NUM[i]<='f'&&NUM[i]>='a')
    34                 NUM[i]-=32;
    35             printf("%c",NUM[i]);
    36         }
    37         printf("
    ");
    38     }
    39     return 0;
    40 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    usaco PROB Checker Challenge 搜索
    usaco Superprime Rib 搜索
    hdu_1056_HangOver_201311071354
    hdu_1049_Climbing Worm_201311061331
    hdu_1048_The Hardest Problem Ever_201311052052
    hdu_1041_Computer Transformation_201311051648
    hdu_1039_Easier Done Than Said_201311051511
    hdu_1038_Biker's Trip Odometer_201311021643
    hdu_1037_Keep on Truckin'_201311021600
    hdu_1036_Average is not Fast Enough_201311021335
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750289.html
Copyright © 2011-2022 走看看