题解 | #大整数的因子#
大整数的因子
https://www.nowcoder.com/practice/3d6cee12fbf54ea99bb165cbaba5823d
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
// 做精度运算时, 先设计一个容纳元素的数据结构, 包括数组, 数组长度。 除法 。 要从数的开头 一个一个地除 , 之后取模计算。
struct BigInt
{
int d[1000] ;
int len = 0 ;
BigInt()
{
memset(d, 0 , 1000) ;
len = 0 ;
}
} ;
int main() {
string t ;
while(cin>>t)
{
if(t == "-1" && t.size() == 2)
{
continue;
}
BigInt num ;
int k = 0 ;
for(int i = 0; i<= t.size() - 1 ; ++ i)
{
num.d[num.len++] = t[i] - '0' ;
}
// for(int i = 0; i<= t.size() - 1 ; -- i)
// {
// cout<<num.d[num.len++] << " ";
// }
// num.len -- ;
string s ;
for(int k = 2 ; k <= 9 ; ++ k)
{
int carry = 0;
for(int i = 0 ; i < num.len ; ++ i ) // 对所有数 看除到最后是否有余数。
{
int tmp = num.d[i] + carry * 10 ;
carry = tmp % k ;
}
if(carry == 0)
{
s.push_back(k + '0') ;
s.push_back(' ') ;
}
}
if(s.size() == 0)
{
cout<<"none"<<endl ;
}
else {
cout<<s<<endl ;
}
}
// }
}
// 64 位输出请用 printf("%lld")
