Epic - Seed Number

Find the seed of a number.

Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible seed for a given number.

辗转相除法,由性质可利用 sqrt(num) <= seed_number <= num/2 缩小范围。

def seed_number(num)
  seed = Math.sqrt(num).to_i
  while seed <= num / 2
    if num % seed == 0
      product = temp = seed
      while temp != 0
        product *= temp%10
        temp /= 10
      end
      return seed if product == num
    end
    seed += 1
  end
end
时间: 2024-08-01 11:13:15

Epic - Seed Number的相关文章

Epic - Decimal Number

Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places are allowed. Theoutput should be an irreducible fraction. E.g.: If the user enters 0.35,the irreducible fraction will be 7/20. 等于找与10000的公约数 def fract

Epic - Desirable Number

A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You know that your rivalhas a strictly numeric password that is 'desirable'. Your close ally has givenyou the number of digits (N) in your rival's password. WAP

dbms_random.seed

语法: DBMS_RANDOM.SEED ( val IN BINARY_INTEGER); DBMS_RANDOM.SEED ( val IN VARCHAR2); val: Seed number or string used to generate a random number 用于生成一个随机数种子,设置种子的目的是可以重复生成随机数,用于调试.否则每次不同,难以调度. 如果不指定随机数参数的种子,oracle将会使用当前时间,用户id,进程id号来生成种子.如果指定的种子相同将会生成

js Math随机数

#2015-8-12 ##Math随机数 ###**1**. JS 随机数(不要问我为什么,百度也说不清,百度最新版) var rand  = (function(){   var today  = new Date();    var seed  = today.getTime();   function rnd(){     seed  = ( seed * 9301 + 49297 ) % 233280;     return seed  / ( 233280.0 );   };   re

不使用Math.random实现随机数。

var rand = (function(){ var today = new Date(); var seed = today.getTime(); function rnd(){ seed = ( seed * 9301 + 49297 ) % 233280; return seed / ( 233280.0 ); }; return function rand(number){ return Math.ceil(rnd(seed) * number); }; })(); console.l

[ActionScript 3.0] AS3中的位图(BitmapData)应用

1.位图使用(模糊)滤镜 //创建一个矩形区域的BitmapData var bmd:BitmapData = new BitmapData(80, 30, false, 0xffffff); //画个红色的矩形 var rect:Rectangle = new Rectangle(20, 10, 40, 10); bmd.fillRect(rect, 0xFF0000); //找到红色矩形的右上顶点 var pt:Point = new Point(rect.left, rect.top);

使用packstack以answer-file的方式部署单节点openstack环境

原来是使用packstack --init-host=myip的方式部署,这样只能是单节点 http://blog.csdn.net/xiangpingli/article/details/51239832 为了使用packstack进行多节点的方式部署openstack,就需要先研究answer-file的方式来部署openstack环境 如下是使用packstack --answer-file的方式部署单节点openstack环境的过程: Packstack –answer-file方式部署

[High Performance Computing] {Udacity} L4: Intro to OpenMP

Getting started with OpenMP These instructions for getting started with OpenMP are repeated in Project 0. They are included here for those students who wish to program with OpenMP now. Vagrant Your first task is to set-up Vagrant on your machine if y

CEE 6640

CEE 6640 Fall 2019HW3: Conditional LogitDue: 10/11/2019Note: For submission please prepare a zip file containing your written report and your Rcode. Name your zip file using the following the format: HW3 FamilyName GivenName.zip(Only zip files will b