3 条题解

  • 1
    @ 2023-10-8 21:25:56

    #include<stdio.h> int main(){ int a,b,c; scanf("%d %d %d",&a,&b,&c); for (int i = 10; i <= 100; i++) { if (i % 3 == a && i % 5 == b && i % 7 == c) { printf("%d\n", i); return 0; } }

    printf("No answer\n"); return 0; }

    • 0
      @ 2025-11-6 20:07:53

      jeight

      #include<iostream>
      using namespace std;
      int main(){
      	int a,b,c;
      	cin >> a >> b >> c;
      	for(int i=10;i<=100;i++){
      	if(i%3==a&&i%5==b&&i%7==c){
      		cout<<i<<'\n';
      		return 0;
      	}
      	}
      	cout<<"No answer"<<'\n';
      		
      	
      	return 0;
      }
      
      • 0
        @ 2025-9-18 22:26:11

        暴力

        from math import sqrt,ceil,gcd,log;re=lambda:map(int,input().strip().split())
        a, b, c = re()
        isFind = False
        for i in range(10, 101):
            if i % 3 == a and i % 5 == b and i % 7 == c:
                print(i)
                isFind = True
        if not isFind:
            print("No answer")
        

        Chinese Remainder Theorem

        对于此题,最小解为 (a_1 M_1 t_1 + a_2 M_2 t_ 2 + a_3 M_3 t_3) (mod M)

        M = 105

        M_1 = 105 / 3 = 35

        M_2 = 105 / 5 = 21

        M_3 = 105 / 7 = 15

        M_i * t_i = 1 (mod m_i) (就是在求逆元,t_i 是 M_i 在模 m_i 意义下的逆元)

        可以试出t_1 = 2, t_2 = 1, t_3 = 1,则最小解 x_0 就是 (70a + 21b + 15c) % 105

        from math import sqrt,ceil,gcd,log;re=lambda:map(int,input().strip().split())
        a, b, c = re()
        res = (70 * a + 21 * b + 15 * c) % 105
        print(res if 10 <= res <= 100 else "No answer")
        
        • 1

        信息

        ID
        132
        时间
        3000ms
        内存
        128MiB
        难度
        5
        标签
        (无)
        递交数
        1251
        已通过
        460
        上传者