zoukankan      html  css  js  c++  java
  • 2019百度之星初赛二 1001 度度熊与数字(因子问题)

    1001 度度熊与数字

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=862&pid=1001

    题目:

     思路:先求出这个数每个位置上的和,可以用字符串处理,sprintf,然后在sqrt(n)内求出n的因子,然后暴力搜索和是因子的倍数的,放入set容器中,因为他是自动排序的容器,所以直接输出即可,注意行末不要有空格

    // 
    // Created by HJYL on 2019/8/17.
    //
    #include <iostream>
    #include <vector>
    #include <map>
    #include <string>
    #include <queue>
    #include <stack>
    #include <set>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstdlib>
    #include<math.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+10;
    ll a[maxn];
    int main()
    {
        //freopen("C:\Users\asus567767\CLionProjects\untitled\text","r",stdin);
        int T;
        scanf("%d",&T);
        while(T--)
        {
            ll n;
            char str[50];
            scanf("%lld",&n);
            sprintf(str,"%lld",n);
            //cout<<str<<endl;
            int res=0;
            int len=strlen(str);
            for(int i=0;i<len;i++)
            {
                res+=(str[i]-'0');
            }
            // cout<<res<<endl;
            int pos=0;
            int a[maxn];
            set<int>st;
            int cnt=0;
            for(ll i=1;i<=sqrt(n);i++)
            {
                if(n%i==0)
                {
                    a[pos++]=i;
                    a[pos++]=n/i;
                }
            }
            for(int i=0;i<pos;i++)
            {
                if(res%a[i]==0)
                    st.insert(a[i]);
            }
            printf("%d
    ",st.size());
            for(auto it=st.begin();it!=st.end();it++)
            {
                if(it==st.begin())
                    printf("%d",*it);
                else
                    printf(" %d",*it);
            }
            printf("
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    pm2
    php 基础知识
    EBADF, read
    php apache
    noah
    ejs
    node linux
    枚举系统进程
    c++ 进程权限的提升
    Liunx的目录结构
  • 原文地址:https://www.cnblogs.com/Vampire6/p/11373518.html
Copyright © 2011-2022 走看看