1001 degree of Bear and digital
Topic links: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=862&pid=1001
topic:
Ideas: the first and this number is obtained for each position, it can be treated with a string, sprintf, then n is determined in the factor sqrt (n), and then search for violence are multiple factors, set into the container because he is the automatic sorting of containers, so you can direct output, pay attention to the end of the line with no spaces
// // 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; }