スター予選Baiduは1001度程度クマとデジタル(ファクターの問題を)ビス

クマとデジタルの1001度

トピックへのリンク:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=862&pid=1001

トピック:

 

 アイデア:最初、この数は各位置について得られ、それはその後、文字列はsprintfで処理することができるN因子SQRT(n)が決定され、そしてその後暴力の検索は、容器内に設定された複数の要素であります彼は、容器の自動選別ですので、あなたが出力を指示することができるので、スペースなしで行の末尾に注意を払います

 

// 
// 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\n",st.size());
        for(auto it=st.begin();it!=st.end();it++)
        {
            if(it==st.begin())
                printf("%d",*it);
            else
                printf(" %d",*it);
        }
        printf("\n");
    }

    return 0;
}

 

おすすめ

転載: www.cnblogs.com/Vampire6/p/11373518.html