Hdu 2053 Switch Game 推结论? 找规律?解题报告

本文探讨了一道关于一系列操作后灯泡最终状态的问题。通过分析得知,在无限次操作后,第n个灯的状态取决于n是否为完全平方数。如果是完全平方数,则灯处于开启状态;反之则关闭。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description

There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).

Input

Each test case contains only a number n ( 0< n<= 10^5) in a line.

Output

Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).

Sample Input

1
5

Sample Output

1
0

Hint

Consider the second test case:

The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …

The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.

思路

可以模拟过好像。。。
话说这道题我的不知道怎么分类。。。
题意:给你n个灯,刚开始全灭,问经过无穷多次操作后,第n个灯状态
对于第i次操作,改变所有i的倍数的状态

发现当操作到n+1次之后肯定不会对n有影响,此题变为操作n次之后的n的状态

下面分析:刚开始n的状态为0,如果对第n个灯操作了偶数次,其状态还是0,
操作奇数次变为1,现在来分析对于n:如果i是n的约数,就会改变n的状态,但是
j=n/i也是n的约数,还会把n的状态改变回来,到这里可以发现当i=n/i的时候,才会
对n的状态发生影响,刚开始n状态为0,如果n是个完全平方数,则会变为1.

代码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int n,k;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        k=(int)sqrt(n)+0.5;
        if (k*k==n) printf("1\n");
        else printf("0\n");
    }
    return 0;
}

短到不行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值