HLG 1882 三原色 && NYLG 77 开灯问题及三原色问题

链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=77

http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1882



解题思路: 用一个数组来表示有N盏灯(或需要涂的板块),并且置0,1来分别表示灯的开关状态;随后一直模拟这些状态即可;


解题代码如下:

#include <stdio.h>

int gcd(int a, int b) {
   return b==0?a:gcd(b, a%b);
}

int main() {
   int x, y, z, n;
   int tmp;
   int i, j , k;
   
   while (scanf("%d%d%d%d", &x, &y, &z, &n) != EOF) { 
      tmp = x*y/gcd(x, y);
      tmp = tmp*z/gcd(tmp, z);
      printf("%d\n", n/tmp);
   }
   return 0;
}

      

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int Kesha[105];

int main() {
    int t;

    scanf("%d", &t);
    while(t--) {
        int n;
        scanf("%d", &n);
        int count = 0;
        memset(Kesha, 0, sizeof(Kesha));
        for(int i=2; i<=n; i++) {
            for(int j=i; j<=n; j++) {
                if(j%i == 0) {
                    Kesha[j] = !Kesha[j];  // 取相反值!
                }
            }
        }
        for(int i=1; i<=n; i++) {
            if(!Kesha[i]) {
                count++;
            }
        }
        printf("%d\n", count);
    }
    return 0;
}


 

其他解法待续,欢迎交流;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值