首页 > 其他分享 >Humble Numbers

Humble Numbers

时间:2024-02-20 19:01:48浏览次数:33  
标签:Humble ++ humble n% long number nth Numbers

打的暴力,样例都要过好久,小脑直接萎缩© ©
Vjudge

  • A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.
    Write a program to find and print the nth element in this sequence
    Input
    The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.
    Output
    For each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output.

  • Sample

    Input	
    1
    2
    3
    4
    11
    12
    13
    21
    22
    23
    100
    1000
    5842
    
    Output
    The 1st humble number is 1.
    The 2nd humble number is 2.
    The 3rd humble number is 3.
    The 4th humble number is 4.
    The 11th humble number is 12.
    The 12th humble number is 14.
    The 13th humble number is 15.
    The 21st humble number is 28.
    The 22nd humble number is 30.
    The 23rd humble number is 32.
    The 100th humble number is 450.
    The 1000th humble number is 385875.
    The 5842nd humble number is 2000000000.
    

    脑残暴力

    点击查看代码
    bool check(int x)
    {
    //	cout<<x<<" ";
    	int tmp=-1;
    	while(x!=tmp&&x)
    	{	
    		tmp=x;
    		if(x%2==0)x/=2;
    		else if(x%3==0)x/=3;
    		else if(x%5==0)x/=5;
    		else if(x%7==0)x/=7;
    		else break;
    //		cout<<x<<endl;	
    	}
    //	cout<<tmp<<endl;
    	if(x&1&&x!=1)return 0;
    	else return 1;
    }
    signed main()
    {
    //	check(26);
    
    	while(scanf("%lld",&k)!=EOF&&k)
    	{
    		a[++cnt]=k;
    	}
    	int l=2;
    	b[1]=1;
    	for(int i=1;i<=cnt;i++)
    	{
    		if(bcnt<=a[i])
    //		else 
    		{
    			while(bcnt<a[i])
    			{
    				if(check(l))b[++bcnt]=l;
    //				cout<<bcnt<<" "<<b[bcnt]<<endl;
    				l++;
    			}
    //			cout<<b[a[i]]<<endl;
    		}
    		cout<<b[a[i]]<<endl;
    	}
    	return 0;
    }
    
    • 正解用到了算数基本定理
      如果会了这个,问题就迎刃而解

      点击查看代码
      	long long n;
      	while(scanf("%lld",&n)&&n)
      	{
      		long long a,b,c,d;
      		for(a=0;n%2==0;n/=2)
      			a++;
      		for(b=0;n%3==0;n/=3)
      			b++;
      		for(c=0;n%5==0;n/=5)
      			c++;
      		for(d=0;n%7==0;n/=7)
      			d++;
      		printf("%lld\n",(1+a)*(1+b)*(1+c)*(1+d));
      	}
      

标签:Humble,++,humble,n%,long,number,nth,Numbers
From: https://www.cnblogs.com/wlesq/p/18023827

相关文章

  • CF55D Beautiful numbers 题解
    题目链接:CF或者洛谷常见知识点组合经典题。首先,一眼数位dp类型题,考虑需要处理些怎样的判断合法数位信息。经典操作对于跟整除有关的判断,数位dp为了减少使用空间,都可以考虑记忆化模数减少空间开销。对于整除若干个数,即整除这若干个数的最小公倍数即可,是一个非常常用......
  • 180. Consecutive Numbers 连续登录n次的用户
    虽然题目很简短,但是很难做啊!属于比较经典的题目,记录一下思路。参考链接:https://leetcode.cn/problems/consecutive-numbers/solutions/21537/sql-server-jie-fa-by-neilsonsrow_number()over([partitionbyvalue_expression,...n]orderbycolumnName)题目解析:1.要获......
  • 无涯教程-MATLAB - 数字(Numbers)
    MATLAB支持各种数字类,包括有符号和无符号整数以及单精度和双精度浮点数,默认情况下,MATLAB将所有数值存储为双精度浮点数。您可以选择将任何数字或数字数组存储为整数或单精度数字,所有数值类型都支持基本数组运算和数学运算。数据类型MATLAB提供以下函数以转换为各种数值数据类......
  • 16 Battling with Numbers
    组合数(2次方级)的组合#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintmod=998244353;voidsolve(){ intn; cin>>n; vector<int>a(n+1); for(inti=1;i<=n;i++)cin>>a[i]; map<int,int>mp; for(inti=1;i&l......
  • 无涯教程-LISP - 数字(Numbers)
    CommonLisp number数据类型包括LISP支持的各种数字。LISP支持的数字类型是-IntegerRatiosFloatComplex下图显示了LISP中可用的数字层次结构和各种数字数据类型-数字类型下表描述了LISP中可用的各种数字类型数据-Sr.No.Datatype&描述1fixnum此数据类型表示......
  • Apple iWork(Pages、Numbers、Keynote)11.0 发布
    苹果今天将其专为iOS和macOS设备设计的iWork应用套件更新为版本11,引入了许多新功能和改进功能。Pages文稿。文档高手,精美不言而喻。进一步了解Pages文稿>Numbers表格。精妙的电子表格,联手做。进一步了解Numbers表格>Keynote讲演。令人难忘的出色提案,轻松打造。进......
  • 『LeetCode』2. 两数相加 Add Two Numbers
    『1』迭代法classSolution{//Iteration//Nisthesizeofl1,Misthesizeofl2//TimeComplexity:O(max(M,N))//SpaceComplexity:O(max(M,N))ifdummyiscountedelseO(1)publicListNodeaddTwoNumbers(ListNodel1,ListNodel2)......
  • CF1866B Battling with Numbers 题解
    前置知识:如果\(p=x^a,q=x^b\),那么\(\gcd(p,q)=x^{\min(a,b)},\operatorname{lcm}(p,q)=x^{\max(a,b)}\)。对于每个\(x\ina_i\),令\(x\)在\(Y\)中的指数为\(d_i\)(实际上不一定),计算贡献时,考虑将\(b_i\)与\(d_i\)分别放入\(p\)和\(q\)中:如果\(b_i<d_i\),贡献为......
  • [Codeforces] CF1744E1 Divisible Numbers (easy version)
    CF1744E1DivisibleNumbers(easyversion)题意给你四个数\(a,b,c,d\),你需要找出一组\(x,y\)使得\(a<x\leqc,b<y\leqd\)并且\(x\cdoty\)能被\(a\cdotb\)整除,如果没有输出-1-1。思路最暴力的思路肯定是枚举,更肯定的一点是会TLE但是注意到,如果\(x\)一定,那么他......
  • C - Sum of Numbers Greater Than Me
    C-SumofNumbersGreaterThanMehttps://atcoder.jp/contests/abc331/tasks/abc331_c 思路由于值可以是重复的,需要记录每出现的值对应的位置,记录在map<int,vector<int>>valpos;此处利用了mapkey的自动排序属性,把所有值进行从小到大做了排序,然后根据valpos......