韩信点兵-算法竞赛入门经典习题2-2

2020-01-23  本文已影响0人  茶酒qqq

韩信点兵

3人一排余a人,5人一排余b人,7人一排余c人,求总共人数?
规定人数不小于10人,不大于100人

#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    // 韩信点兵 
    // 3人一排余a人,5人一排余b人,7人一排余c人,求总共人数? 
    // 规定人数不小于10人,不大于100人
    int flag=0;
    int a,b,c;
    cin>>a>>b>>c;
    
    for(int i=10+b;i<100;i+=5){
        if((i-a)%3==0 && (i-c)%7==0){
            flag=1;
            cout<<"可能是:"<<i<<endl;
        }
    }
    if(!flag){
        cout<<"无解"<<endl; 
    }
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读