您的位置:首页 > 其它

章三例题5——UVA 1583 Degit Generator

2017-02-27 00:12 369 查看
题意就是如果x加上x的各个数字的和得到y,则说x是y的生成元,然后告诉y,求x的最小生成元。

然后因为n比较小,然后只用输入一组,直接枚举是可以过的。

据说可以打表,现在还没有接触到

http://blog.csdn.net/a27038/article/details/55048971

代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int N;
scanf("%d",&N);
int len=1;
int flag=0;
int temp=N;
while(temp)
{
if(temp/10!=0)
len++;
temp=temp/10;
}
int j=0;
for(int i=N-len*10;i<N;i++)
{
j=i;
int g=i;
while(g)
{
j+=g%10;
g=g/10;
}
if(j==N)
{
flag=1;
cout<<i<<endl;
break;
}
}
if(flag==0)
printf("0\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: