第十届蓝桥杯B组省赛第D题

试题 D: 数的分解 (40785

 

【问题描述】 

把 2019 分解成 3 个各不相同的正整数之和,并且要求每个正整数都不包 含数字 2 和 4,一共有多少种不同的分解方法? 

注意交换 3 个整数的顺序被视为同一种方法,例如 1000+1001+18 和 1001+1000+18 被视为同一种。

#include <stdio.h>

int main(){

    int i,j,k;

    int ii,jj,kk;

    int cc=1,z,temp=0;

    for(i=1;i<2019;i++)

    {

        for(j=i+1;j<2019;j++)

        {

            for(k=j+1;k<2019;k++)

            {

                if(i+k+j==2019){

                    ii=i;jj=j;kk=k;cc=1;

                    while(ii){

                        z=ii%10;

                        if(z==2&&ii!=0){

                            cc=0;break;

                        }

                        if(z==4&&ii!=0){

                            cc=0;break;

                        }

                        ii=ii/10;

                    }

                    while(jj){

                        z=jj%10;

                        if(z==2&&jj!=0){

                            cc=0;break;

                        }

                        if(z==4&&jj!=0){

                            cc=0;break;

                        }

                        jj=jj/10;

                    }

                    while(kk){

                        z=kk%10;

                        if(z==2&&kk!=0){

                            cc=0;break;

                        }

                        if(z==4&&kk!=0){

                            cc=0;break;

                        }

                        kk=kk/10;

                    }

                    if(cc) temp++;

                }

            }

        }

    }

    printf("%d",temp);          //40785

}

posted @ 2019-11-14 13:53  tly2022  阅读(206)  评论(0编辑  收藏  举报