您的位置:首页 > 大数据 > 人工智能

2016夏季练习——水题(AI)

2016-08-02 09:31 281 查看
来源:CF460B

反过来枚举位数和,代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const LL INF=1e9;
LL a,b,c;
LL ans[100];
LL pow_m(LL x,LL a){
LL ans=1;
for(int i=0;i<a;i++)
ans*=x;
return ans;
}
LL fun(LL x,LL a){
return b*pow_m(x,a)+c;
}
bool judge(LL x,LL i){
LL res=0;
while(x){
res+=x%10;
x/=10;
}
if(i==res) return 1;
else return 0;
}
int main()
{
int cnt=0;
scanf("%lld%lld%lld",&a,&b,&c);
for(int i=1;i<=81;i++){
LL x=fun(i,a);
if(judge(x,i)&&x<INF) {
ans[cnt++] = x;
}
}
cout<<cnt<<endl;
if(cnt){
cout<<ans[0];
for(int i=1;i<cnt;i++)
cout<<" "<<ans[i];
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: