zoukankan      html  css  js  c++  java
  • HDU 4432 Sum of divisors (水题,进制转换)

    题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和。

    析:按它的要求做就好,注意的是,是因数,不可能有重复的。。。比如4的因数只有一个2,还有就是输出10进制以上的,要用AB。。

    但我用的是ab。。又没读好题。。。。活该WA了好几次。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <stack>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 10 + 5;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int a[70];
    
    int solve(int x){
        int ans = 0;
        while(x){
            ans += (x % m) * (x % m);
            x /= m;
        }
        return ans;
    }
    
    int main(){
        while(scanf("%d %d", &n, &m) == 2){
            int t = sqrt(n+0.5);
            int ans = 0;
            for(int i = 1; i <= t; ++i){
                if(n % i == 0){
                    ans += solve(i);
                    if(n / i != i)  ans += solve(n/i);
                }
            }
            int cnt = 0;
            while(ans){
                a[cnt++] = ans % m;
                ans /= m;
            }
            for(int i = cnt-1; i >= 0; --i)
                if(a[i] < 10)  printf("%d", a[i]);
                else printf("%c", 'A'+a[i]-10);
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    Markdown引用图片,且不使用网上链接的解决方法
    测试
    sudo用户权限添加问题
    windows安装ipython
    ansible基本操作
    mysql用户权限操作
    解决windows7系统的快捷方式无法添加到任务栏
    linux下查看磁盘分区的文件系统格式
    mail客户端POP和IMAP协议
    linux设置history历史记录
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5762680.html
Copyright © 2011-2022 走看看