leetcode 263. Ugly Number(丑数)

LeetCode每日一题(263. Ugly Number) An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.Given an integer n, return true if n is an ugly number.Example 1:Explanation: 6 = 2 × 3Example 2:Explanation: 1 has no prime factors, therefore all of its prime factors are 阅读详情

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

Given an integer n, return true if n is an ugly number.

Example 1:

Input: n = 6
Output: true
Explanation: 6 = 2 × 3
Example 2:

Input: n = 1
Output: true
Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.

丑数:必须是正数,因子分解的话只有2,3,5.
1也是丑数。
判断数字n 是不是丑数。

思路:

首先丑数必须得是正数,负数直接返回false.

然后就对2,3,5一直分解好了,直到不能再分解。
最后剩下的必须得是1(因为其他的就可以进一步分解为1x它自己,就不只2,3,5这3个因子)。

public boolean isUgly(int n) {
    if(n <= 0) return false;
    
    while(n % 2 == 0) n /= 2;
    while(n % 3 == 0) n /= 3;
    while(n % 5 == 0) n /= 5;
    
    if(n == 1) return true;
    return false;
}
从零构建物联网数据中台:MQTT协议、Node.js服务、MongoDB与InfluxDB双存储及React可视化实战 本文详细介绍了从零构建物联网数据中台的完整实战方案。通过采用MQTT协议作为设备通信标准,结合Node.js搭建高并发数据处理服务,并创新性地使用MongoDB与InfluxDB双存储架构分别管理设备元数据与海量时序数据,最后利用React构建了实时数据可视化控制台。该架构有效解决了物联网项目中数据异构、查询性能低下等核心痛点,为构建高效、可扩展的物联网平台提供了清晰路径。 阅读详情

相关推荐

superpowers-中文使用说明

《obra/superpowers:AI辅助开发的流程纪律工具集》 摘要:obra/superpowers是一套面向AI辅助软件开发的系统化流程规范,包含14个核心技能,强调"先理解后行动"的纪律性开发方法。该工具集定义了从头脑风暴到代码评审的完整工作流,要求严格遵循测试驱动开发、子代理隔离执行等原则。核心特色包括:1) 任何实现前必须完成设计和评审;2) 采用红-绿-重构的TDD循环;3) 复杂任务通过独立子代理串行处理;4) 所有产出需经过双重验证(规格合规+代码质量)。该工具集特别注重文档化和可验证性

qq_22786633的博客 775

【题型总结】找到第n个自定义数 | 丑数系列 + 神奇数字

【题型总结】找到第n个自定义数 | 丑数系列 + 神奇数字

Tikitian的博客 1133

LAP-D协议概述

Q.921协议由称为LAPD(链路访问协议-D通道),与HDLC的关系密切,它是在ISDN D通道上使用的数据链路协议。 注:http://www.freesoft.org/CIE/Topics/125.htm LAP-D的帧格式 标志、位填充技术和FCS校验计算与HDLC一致。 16位的地址包括C/R字段、SAPI(服务访问点标识)和TEI(端点标识)。TEI用于区分使用相同ISDN...

系统运维 1919

每日一题 day 42 (DP topic)

文章目录problemapproach problem 264. Ugly Number II An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the nth ugly number. Example 1: Input: n = 10 Output: 12 Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 1

NP_hard的博客 335

Pi0 项目复现及项目问题解决方案(全网抢先发布~)

Pi0 项目复现及项目问题解决方案(全网抢先发布~)

m0_68167062的博客 2281

手把手教你用迅为RK3588核心板搭建无人机飞控系统(附完整开发指南)

本文详细介绍了如何利用迅为RK3588核心板搭建高性能无人机飞控系统,涵盖硬件选型、开发环境配置、传感器数据融合、控制算法实现及系统测试全流程。RK3588凭借其强大的计算能力和丰富接口,为无人机控制解决方案提供了理想平台,特别适合需要实时处理的复杂飞行任务。

weixin_29062255的博客 385

LeetCode每日一题(264. Ugly Number II)

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.Given an integer n, return the nth ugly number.Example 1:Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.Example 2:Explanation: 1

wangjun861205的博客 410

PLC作为Modbus TCP客户端

PLC作为Modbus TCP客户端,Modbus Slave作为服务器

soledad_chao的博客 4384

263. 丑数(javascript)263. Ugly Number

263. 丑数(javascript)263. Ugly Number

ingenuou_的博客 1659

Abaqus 2023 保姆级安装避坑指南:从环境变量到许可证配置,一次搞定

本文提供Abaqus 2023的详细安装指南,涵盖环境变量设置、许可证配置等关键步骤,帮助用户避开常见安装陷阱。通过系统环境检查、目录结构规划、许可证服务器安装及Java环境配置等实用技巧,确保顺利完成安装并优化软件性能。

weixin_42524276的博客 430

本届挑战赛亚军方案:基于大模型和多AGENT协同的运维

我们分别构建了异常检测基础模型,一旦系统接受到异常即会通知LLM主管Agent,主管Agent对异常问题进行决策与子领域Agent进行桥接,多个子领域Agent协同工作,实现运维故障自动诊断和多个任务模型的编排,提升运维效率。

weixin_52705010的博客 2300

LeetCode 263 Ugly Number(丑数)

翻译写一个程序来检查给定的数字是否是丑数(Ugly number)。丑数是一个正数,它的质因子只包括2、3、5。例如,6、8是丑数,而因为包含了7这个因子,所以14不是丑数。请注意,1通常被视为一个丑数。原文Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbe

nomasp 3188

5分钟搞懂知识抽取:如何把非结构化数据变成知识图谱的宝藏?

本文通过一个电商评论分析实战案例,详细解析了如何利用spaCy、Neo4j等工具,将非结构化文本数据转化为结构化知识图谱的完整流程。文章重点阐述了知识抽取的核心步骤,包括命名实体识别、关系抽取以及知识存储与查询,帮助读者快速掌握将数据转化为知识宝藏的关键技术。

weixin_29054245的博客 238

LeetCode 263. Ugly Number 丑数

题目:编写一个程序判断给定的数是否为丑数。丑数就是只包含质因数 2, 3, 5 的正整数。示例 1:输入: 6 输出: true 解释: 6 = 2 × 3示例 2:输入: 8 输出: true 解释: 8 = 2 × 2 × 2 示例 3:输入: 14 输出: false 解释: 14 不是丑数,因为它包含了另外一个质因数 7。说明:1 是丑数。输入不会超过 32 位有符号整数的范围: [−2...

zhangzhetaojj的博客 262

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[leetcode]263. Ugly Number丑数

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly si

CloudShadow_的博客 384

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

php实现丑数,Leetcode基础刷题之PHP解析(263. Ugly Number)

Leetcode基础刷题之PHP解析(263. Ugly Number)由 吴亲库里 创建于1年前, 最后更新于 1年前版本号 #11616 views0 likes0 collects2019-4-17星期三开始吧题目描述判断一个数是不是丑数.丑数的定义是只包含因子2,3,5的数字.1是第一个丑数.题目分析不断的去除以这个数,如果剩余的数字是1的话就是丑数,下面的两种写法原理都是一样的.我们只要...

weixin_29021291的博客 105

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

leetcode 263, 264, 1201, 313. Ugly Number I, II, III, Super Ugly Number(leetcode 丑数问题合集)

263. Ugly Number https://leetcode.com/problems/ugly-number/ 本题题解由下面的 264. Ugly Number II 改造而来,所以效率会比较低。 class Solution { public boolean isUgly(int n) { if (n == 1) return true; if (n > 2125764000) return false; int[] dp = ne

寒泉 5万+

LeetCode-263.264. Ugly Number II (JAVA)丑数

LeetCode-263.264. Ugly Number II (JAVA)丑数

mine_song的博客 1359

Leetcode 263.丑数(Ugly Number)

Leetcode 263.丑数 1 题目描述(Leetcode题目链接)   编写一个程序判断给定的数是否为丑数。丑数就是只包含质因数 2, 3, 5 的正整数。示例: 输入: 6 输出: true 解释: 6 = 2 × 3 输入: 8 输出: true 解释: 8 = 2 × 2 × 2 输入: 14 输出: false 解释: 14 不是丑数,因为它包含了另外一个质因数 7。 说明:...

qq_39378221的博客 256

【LeetCode】263. Ugly Number 丑数(Easy)(JAVA)

【LeetCode】263. Ugly Number 丑数(Easy)(JAVA) 题目地址: https://leetcode.com/problems/ugly-number/ 题目描述: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 1: Input

qq_16927853的博客 213

leetcode 263.264.313 Ugly Number 丑数

第3题题目 Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4

Mi_soon的博客 421

LeetCode 263. Ugly Number 丑数(Java)

题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 1: Input: 6 Output: true Explanation: 6 = 2 ...

qq_41878358的博客 267

leetcode 263. Ugly Number 丑数

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it

JackZhangNJU的专栏 528

leetcode 263. Ugly Number丑数

leetcode 263. Ugly Number丑数

Shauna_Wu的博客 603

LeetCode - 263 - 丑数(ugly-number)

Create by jsliang on 2019-07-18 17:15:35Recently revised in 2019-07-18 17:43:26一 目录不折...

weixin_41806099的博客 182

判断是否为丑数(Ugly Number)(leetcode-263)

“丑数”是正数,且质数因子只包含2、3、5。(Ugly numbers are positive numbers whose prime factors only include 2, 3, 5。)关键在于:丑数一定是有限个2、3、5的乘积,因为所有的正整数都能分解成1与一个或多个素数的乘积。如果一个数是丑数,那么反复除以2、3、5后,一定会是1;如果一个数不是丑数,那么反复除以2、3、5后,一定还

一路洒满阳光! 4679
上一篇: yolact ncnn保姆级源码解读(结合paper)
下一篇: leetcode 1926. Nearest Exit from Entrance in Maze(迷宫最近的出口)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值