Problem F: 深入浅出学算法007-统计求和

Description

求含有数字a且不能被a整除的4位整数的个数,并求这些整数的和

Input

多组测试数据,先输入整数T表示组数然后每组输入1个整数a(1<=a<=9)

Output

对于每组测试数据输出一行,每行2个数分别是个数与和

Sample Input

1
3

Sample Output

2112 10568016
#include <stdio.h>
int search(int x,int y)
{
    int a,b,count=0;
    b=x;
    while(x!=0)
    {
        a=x%10;
        x=x/10;
        if(a==y&&b%y!=0)
        {
            count++;
            break;
        }
    }
    if(count==0)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}
int main()
{
    long long int sum;
    int t,a;
    int i,count;
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        {
            count=sum=0;
            scanf("%d",&a);
            for(i=1000;i<10000;i++)
            {
                if(search(i,a))
                {
                    sum+=i;
                    count++;
                }
            }
            printf("%d %lld\n",count,sum);
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/chenlong991223/p/10169528.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值