zoukankan      html  css  js  c++  java
  • 丑数,4遍提交耻辱啊。

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
    1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …
    shows the first 11 ugly numbers. By convention, 1 is included.
    Write a program to find and print the 1500’th ugly number.
    Input
    There is no input to this program.
    Output
    Output should consist of a single line as shown below, with ‘< number >’ replaced by the number
    computed.
    Sample Output
    The 1500’th ugly number is < number >.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<set>
    #include<algorithm>
    using namespace std;
    int main()
    {
        set<int> a;
        set<int> b;
        set<int>::iterator p1,p2;
        a.insert(1);
        a.insert(2);
        a.insert(3);
        a.insert(4);
        a.insert(5);
        a.insert(6);
        a.insert(8);
        a.insert(9);
        for(p1=a.begin();p1!=a.end();p1++)
        {
            a.insert(*p1*2);
            a.insert(*p1*3);
            a.insert(*p1*5);
            if(a.size()>1600) break;
        }
        p1=a.begin();
        for(int i=1;i<1500;i++)
        {
            p1++;
        }
        	printf("The 1500'th ugly number is %d.
    ",*p1);
    }
    

    算出来的数,跟网上查的是一样的,四遍就是过不去,后来发现,自己“ 点 ”的位置不对。换行符没加。活该不对。

  • 相关阅读:
    scroll
    "严格模式" use strict 详解
    thymeleaf 模板布局
    前端性能优化
    原生的强大DOM选择器querySelector
    thymeleaf 基本语法
    读书笔记JavaScript中的全局对象
    JavaScript中getBoundingClientRect()方法详解
    JavaScript 中的内存泄漏
    jsonp 跨域原理详解
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12799081.html
Copyright © 2011-2022 走看看