智商压制的一道题

这个题有个数学定理:

一般数(非完全平方数)的因子有偶数个

完全平凡数的因子有奇数个

开开关的时候,第i个灯每到它的因子一轮的时候就会拨动一下,也就是每个灯拨动的次数是它的因子数

而拨动偶数次是关,拨动奇数次是开

现在就是求哪些数的因子有奇数个,也就是求n以内的完全平凡数

这里又有一个定理:

n以内的完全平方数个数是sprt(n)

所以代码很简单

public int bulbSwitch(int n) {
return (int)Math.sqrt(n);
}

[LeetCode]319. Bulb Switcher灯泡开关的更多相关文章

  1. 319 Bulb Switcher 灯泡开关

    初始时有 n 个灯泡关闭. 第 1 轮,你打开所有的灯泡. 第 2 轮,每两个灯泡切换一次开关. 第 3 轮,每三个灯泡切换一次开关(如果关闭,则打开,如果打开则关闭).对于第 i 轮,你每 i 个灯 ...

  2. LeetCode 319 ——Bulb Switcher——————【数学技巧】

    319. Bulb Switcher My Submissions QuestionEditorial Solution Total Accepted: 15915 Total Submissions ...

  3. [LeetCode] Bulb Switcher 灯泡开关

    There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...

  4. Leetcode319. Bulb Switcher灯泡开关

    初始时有 n 个灯泡关闭. 第 1 轮,你打开所有的灯泡. 第 2 轮,每两个灯泡你关闭一次. 第 3 轮,每三个灯泡切换一次开关(如果关闭则开启,如果开启则关闭).第 i 轮,每 i 个灯泡切换一次 ...

  5. Java [Leetcode 319]Bulb Switcher

    题目描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off ...

  6. LeetCode 319. Bulb Switcher

    There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...

  7. Leetcode 319 Bulb Switcher 找规律

    有n盏关着的灯,第k轮把序号为k倍数的关着的灯打开,开着的灯关闭. class Solution { public: int bulbSwitch(int n) { return (int)sqrt( ...

  8. 【LeetCode】319. Bulb Switcher 解题报告(Python)

    [LeetCode]319. Bulb Switcher 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/bulb ...

  9. 319. Bulb Switcher

    题目: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off ev ...

随机推荐

  1. java集合类(新手也能掌握)

    文章目录 1.集合概述 (1)集合: (2)集合分类: 2.Collection接口 3.List接口 (1)List接口简介 (2)ArrayList集合 (3)LinkedList集合 (4)It ...

  2. C++20初体验——concepts

    引子 凡是涉及STL的错误都不堪入目,因为首先STL中有复杂的层次关系,在错误信息中都会暴露出来,其次这么多类和函数的名字大多都是双下划线开头的,一般人看得不习惯. 一个经典的错误是给std::sor ...

  3. 注意当cin.getline、和cin 合用的时候

    1. getline有两种,一个是string的(getline(cin,s)),一个是istream的(cin.getline(s,maxsize,delim)). 2. 当用cin输入了数据后,在 ...

  4. PyQt(Python+Qt)学习随笔:QListView的gridSize属性

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QListView的gridSize属性用于控制视图中数据项排列所在网格的大小,gridSize默认 ...

  5. windows cmd 链接远程mysql服务器

    我要链接的mysql 所在ip:192.168.0.110    用户名:root  密码:123 那么: 打开cmd 输入: mysql -h192.168.0.110 -uroot -p123 即 ...

  6. sudo rm -rf /*含义

    sudo -----  管理员权限 rm ------ remove 移除 rf ------ recursive递归  force强制 /* ------ 目录下所有文档

  7. 【译】理解Rust中的Futures (一)

    原文标题:Understanding Futures In Rust -- Part 1 原文链接:https://www.viget.com/articles/understanding-futur ...

  8. tp5使用PHPExcel(下载引入/composer与模板/生成方式搭配使用)

    PHPExcel使用 一:引入 tp5.0,tp5.1: 1:composer方式 a:根目录下执行:composer require phpoffice/phpexcel b:引入(可new \PH ...

  9. windows上mysql5.7服务启动报错

    安装之后,启动服务 net start mysql,无法启动,日志报错缺少一些系统表,mysql.user等表 解决办法: bin目下执行:mysqld --initialize-insecure - ...

  10. 04-flask-模版基础

    Jinja2 概念 Jinja2:是 Python 下一个被广泛应用的模板引擎,是由Python实现的模板语言,他的设计思想来源于 Django 的模板引擎,并扩展了其语法和一系列强大的功能,其是Fl ...