2019百度之星·初赛二|度度熊与数字
作者:互联网
代码:
#include<iostream>
#include<cmath>
using namespace std;
int gcd(int m,int n);
int main(){
int T;
cin>>T;
int b[9]={0};
int c[1000]={0};
int f=0;
for(int i=0;i<T;i++){
int V;
cin>>V;
int a[9]={0};
int k=0;
int U=V;
while(U!=0){
a[k]=U%10;
U/=10;
k++;
}
int count=0;
for(int j=0;j<k;j++){
count+=a[j];
}
int m=gcd(V,count);
int p=0;
for(int x=1;x<=sqrt(m);x++){
if(m%x==0){
b[p]=x;
p++;
if(x==sqrt(m))
break;
b[p]=m/x;
p++;
}
}
for(int y=1;y<p;y++){
for(int z=0;z<p-y;z++){
if(b[z]>b[z+1]){
int temp=b[z];
b[z]=b[z+1];
b[z+1]=temp;
}
}
}
c[f]=p;
f++;
for(int y=0;y<p;y++){
c[f]=b[y];
f++;
}
}
int r=0;
for(int t=0;t<T;t++){
cout<<c[r]<<" "<<endl;
int s=c[r];
for(int v=0;v<s;v++){
cout<<c[++r]<<" ";
}
r++;
cout<<endl;
}
return 0;
}
int gcd(int m,int n){
int r=n;
while(m%n!=0){
r=m%n;
m=n;
n=r;
}
return r;
}
标签:10,temp,int,初赛,++,2019,度度,include 来源: https://blog.csdn.net/jilli_jelly/article/details/100051833