首页 > 试题广场 >

一的个数

[编程题]一的个数
  • 热度指数:3969 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
NowCoder总是力争上游,凡事都要拿第一,所以他对“1”这个数情有独钟。爱屋及乌,他也很喜欢包含1的数,例如10、11、12……。不仅如此,他同样喜欢任意进制中包含1的数。当然,其中包含1的个数越多他越喜欢。你能帮他统计一下某个数在特定的进制下1的个数吗?

输入描述:
输入有多组数据,每组数据包含一个正整数n (1≤n≤2147483647)和一个正整数r (2≤r≤16)。
其中n为十进制整数,r为目标进制。


输出描述:
对应每组输入,输出整数n转换成r进制之后,其中包含多少个“1”。
示例1

输入

1 2<br/>123 16

输出

1<br/>0

python solution:

def baseN(num, b):
    return ((num == 0) and "0") or (baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
while True:
    try:
        a,b=map(int,input().split())
        print(baseN(a,b).count("1"))
    except:
        break
发表于 2017-10-11 06:17:30 回复(2)
#include <iostream>
using namespace std;
void one(long long n, int r)
{
    int temp = 0, ans = 0;
    while (n != 0)
    {
        temp = n % r;
        if (temp == 1)
        {
            ans++;
        }
        n = n / r;
    }
    cout << ans << endl;
}
int main()
{
    long long n = 0;
    int r = 0;
    while (cin >> n >> r)
    {
        one(n, r);
    }
    return 0;
}

发表于 2018-08-17 20:10:51 回复(0)
importjava.util.Scanner;
publicclassMain {
    publicstaticvoidmain(String[] args) {
        Scanner scanner = newScanner(System.in);
        while(scan.hasNext()){
            intten = scanner.nextInt();
            intother = scanner.nextInt();
            intcount = transferOther(ten,other);
            System.out.println(count);
        }
    }
    privatestaticinttransferOther(longten, intother) {
        longshang = -1;
        longyushu = -1;
        intcount = 0;
        while(shang!=0){
            shang = ten/other;
            yushu = (int)ten%other;
            if(yushu == 1) {
                count++;
            }
            ten = shang;
        }
        returncount;
    }
}

编辑于 2018-07-02 15:03:32 回复(0)
#include <stdio.h>

int main(){
	long n;
	int r, cnt;
	while(scanf("%ld %d", &n, &r)!=EOF){
		cnt = 0;
		while(n!=0){
			if(n % r == 1){
				cnt ++;
			}
			n = n / r;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

发表于 2017-07-22 14:22:13 回复(0)
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		BigInteger n; int r;String str;
		while(in.hasNext()){
			n = in.nextBigInteger();
			r = in.nextInt();
			int count = 0;
		    str = n.toString(r);
			for(int i = 0; i< str.length(); i++){
				if(str.charAt(i)=='1'){
					count++;
				}
			}
			System.out.println(count);
			
		}
	}
}

发表于 2016-10-05 11:33:58 回复(0)
#include<stdio.h>
int countOne(int num, int p)
{   
    int count=0;
	while(num)
	{
		if(num%p==1) count++;
		num/=p;
	}
	return count;
}

int main()
{   
    int n,p;
	while(scanf("%d %d",&n,&p)!=EOF)
	{
		printf("%d\n",countOne(n,p));
	}
}

发表于 2016-09-19 13:40:53 回复(0)
求解!!!

我的代码在本地devc++运行用例输出都是正确的,但是不知道为什么就是在牛客上AC不了....崩溃了...求大神指点!
因为最近学了递归所以用递归写了一下。
#include<iostream>
using namespace std; 
int isOne(int a,int b,int re); //求出1的个数的函数
int main(){
	int a=0,b=0;
	int result=0;
	while(cin>>a>>b){
		int re=0;
		result = isOne(a,b,0);
		cout<<result<<endl;
	}
	return 0;
}
//a是目标数,b是进制,re是1的数量
int isOne(int a,int b,int re){
	if(a/b==0){
		if(a%b==1){
			re++;
		}
		return re;
	}else{
		if(a%b==1){
			re++;
		}
		isOne(a/b,b,re); //这里用了一下递归
	}
	
}

牛客给的错误提示:
用例输入为:1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 8 10 8 11 8 12 8 13 8 14 8 15 8 16 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 9 10 9 11 9 12 9 13 9 14 9 15 9 16 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 11 10 12 10 13 10 14 10 15 10 16 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 11 11 11 12 11 13 11 14 11 15 11 16 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12 9 12 10 12 11 12 12 12 13 12 14 12 15 12 16 13 2 13 3 13 4 13 5 13 6 13 7 13 8 13 9 13 10 13 11 13 12 13 13 13 14 13 15 13 16 14 2 14 3 14 4 14 5 14 6 14 7 14 8 14 9 14 10 14 11 14 12 14 13 14 14 14 15 14 16 15 2 15 3 15 4 15 5 15 6 15 7 15 8 15 9 15 10 15 11 15 12 15 13 15 14 15 15 15 16 16 2 16 3 16 4 16 5 16 6 16 7 16 8 16 9 16 10 16 11 16 12 16 13 16 14 16 15 16 16 17 2 17 3 17 4 17 5 17 6 17 7 17 8 17 9 17 10 17 11 17 12 17 13 17 14 17 15 17 16 18 2 18 3 18 4 18 5 18 6 18 7 18 8 18 9 18 10 18 11 18 12 18 13 18 14 18 15 18 16 19 2 19 3 19 4 19 5 19 6 19 7 19 8 19 9 19 10 19 11 19 12 19 13 19 14 19 15 19 16 20 2 20 3 20 4 20 5 20 6 20 7 20 8 20 9 20 10 20 11 20 12 20 13 20 14 20 15 20 16 21 2 21 3 21 4 21 5 21 6 21 7 21 8 21 9 21 10 21 11 21 12 21 13 21 14 21 15 21 16 22 2 22 3 22 4 22 5 22 6 22 7 22 8 22 9 22 10 22 11 22 12 22 13 22 14 22 15 22 16 23 2 23 3 23 4 23 5 23 6 23 7 23 8 23 9 23 10 23 11 23 12 23 13 23 14 23 15 23 16 24 2 24 3 24 4 24 5 24 6 24 7 24 8 24 9 24 10 24 11 24 12 24 13 24 14 24 15 24 16 25 2 25 3 25 4 25 5 25 6 25 7 25 8 25 9 25 10 25 11 25 12 25 13 25 14 25 15 25 16 26 2 26 3 26 4 26 5 26 6 26 7 26 8 26 9 26 10 26 11 26 12 26 13 26 14 26 15 26 16 27 用例输出为:1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 2 1 2 1 0 0 0 0 0 0 0 0 0 0 0 2 0 1 2 1 0 0 0 0 0 0 0 0 0 0 3 1 1 1 2 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 2 1 0 0 0 0 0 0 0 0 2 1 1 1 1 1 2 1 0 0 0 0 0 0 0 2 2 0 0 1 1 1 2 1 0 0 0 0 0 0 3 1 0 1 1 1 1 1 2 1 0 0 0 0 0 2 2 0 0 0 1 1 1 1 2 1 0 0 0 0 3 3 1 0 1 1 1 1 1 1 2 1 0 0 0 3 2 0 0 0 0 1 1 1 1 1 2 1 0 0 4 1 0 0 0 1 1 1 1 1 1 1 2 1 0 1 2 1 1 0 0 0 1 1 1 1 1 1 2 1 2 1 2 0 0 0 1 1 1 1 1 1 1 1 2 2 0 1 0 0 0 0 0 1 1 1 1 1 1 1 3 1 1 0 1 0 0 1 1 1 1 1 1 1 1 2 0 2 0 0 0 0 0 0 1 1 1 1 1 1 3 1 3 1 0 0 0 0 1 1 1 1 1 1 1 3 2 2 0 0 1 0 0 0 0 1 1 1 1 1 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1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

但是我自己在本地试了一下输出为:
我真的不明白,这输出不是没问题吗?QAQ
发表于 2021-09-21 16:28:25 回复(0)
import java.util.Scanner;

public class Main {
    public static String f(int n, int base) {
        if (n == 0) return "";
        return f(n / base, base) + ((n % base) >= 10 ? "" : (n % base));

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int base = in.nextInt();
            int cnt = 0;
            String s = f(n, base);
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '1') cnt++;
            }
            System.out.println(cnt);
        }
    }
}
发表于 2021-06-06 15:21:42 回复(0)
#include <iostream>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r){
		int num=0;
		while(n){
			int temp=n%r;
			if(temp==1){
				num++;
			}
			n/=r;
		}
		cout<<num<<endl;
	}
} 

发表于 2020-03-29 15:32:15 回复(0)


水题一道。。。
进制转换的题,模拟手动进制转换即可。

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int n = 0, r = 0;
    //scanf返回值为正确输入数据的变量个数,当一个变量都没有成功获取数据时,此时返回-1
    while (scanf("%d %d", &n, &r) != - 1) {
        int count = 0;
        //只要n != 0,则说明还需要进位转换
        while (n != 0) {
            if (n % r == 1) {
                //余数为1,即进制转换后这位出现了1
                count += 1;
            }
            n /= r;
        }
        printf("%d\n", count);
    }
    return 0;
}
————————————————
版权声明:本文为CSDN博主「hestyle」的原创文章,遵循 CC 4.0 BY 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://hestyle.blog.csdn.net/article/details/104659929

编辑于 2020-03-04 19:20:36 回复(0)
#include <stdio.h>
#include <stdlib.h>
 
int exchange(int, int);//进制转换
 
int main()
{
    int n, r;
    while(~scanf("%d %d", &n, &r))
    {
        printf("%d\n", exchange(n, r));
    }
}
 
int exchange(int n, int r)
{
    int count = 0;
    while(n)
    {
        if(n % r == 1)
            count++;
        n = n/r;
    }
    return count;
}

编辑于 2020-03-03 12:41:32 回复(0)
#include<stdio.h>
int main(){
    long num,jinzhi;
    while(scanf("%ld %ld", &num, &jinzhi) != EOF){
        int count = 0;
        while(num > 0){
            if(num % jinzhi == 1) count++;
            num /= jinzhi;
        }
        printf("%ld\n", count);
    }
    return 0;
}

发表于 2019-03-27 18:04:12 回复(0)
#include <iostream>
using namespace std;

int main()
{     int n, r;     cin >> n >> r;     int cnt = 0;     while(n / r != 0)     {         if (n == 1)         {             cnt++;         }         n = n / r;     }     if (n % r == 1)     {         cnt++;     }         cout << cnt << endl;

}

没有输出,不知道为什么
发表于 2018-09-18 15:21:51 回复(0)
写了一个进制转换
然后统计输出。
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
    int n, r;
    int i = 0;
    char ascii[] = { 'A','B','C','D','E','F' };
    vector<int> out;
    while (cin >> n >> r)
    {
        i = 0;
        while (n)
        {
            i++;
            int tempR = pow(r, i);
            int temp = n - (n / tempR)*tempR;
            out.push_back(temp / (pow(r,i-1)));
            n = n - temp;
            //cout << temp / (pow(r, i - 1) )<< endl;
        }
        int count = 0;
        for (int j = 0; j < out.size(); j++)
        {
            if (out[j] == 1)
            {
                count++;
            }
            /*
            if (out[out.size() - j - 1] >= 10)
            {
                cout << ascii[out[out.size() - j - 1] - 10];
            }
            else
                cout << out[out.size() - j - 1];
            if (j == out.size() - 1)
            {
                cout << endl;
            }
            */
        }
        out.clear();
        cout << count << endl;
    }
}

发表于 2018-08-12 17:21:44 回复(0)
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
intmain()
{
    intn,r;
    while(cin>>n>>r)
    {
        string s;
        while(n>0)
        {
            s+=char('0'+n%r);
            n=n/r;
        }
        cout<<count(s.begin(),s.end(),'1')<<endl;
    }
    return0;
}
发表于 2018-04-05 09:39:51 回复(0)
#include <stdio.h>
int Switch(intn, intr, int*a);
int main()
{
    int n;
    int r;
    int i;
    int a[10000];
    while(scanf("%d %d", &n, &r)!=EOF)
    {
        int count=0;
        int len = Switch(n, r, a);
        for(i=0;i<len;i++)
        {
            if(a[i]==1)
            {
                count++;
            }
        }
        printf("%d\n", count);
    }
    return 0;
}
int Switch(int n, int r, int *a)
{
    int i=0;
    while(n!=0)
    {
        a[i] = n % r;
        i++;
        n /= r;
    }
    return i;
}

发表于 2017-11-27 18:25:17 回复(0)
.........为什么没有进制的转换也能通过....
----------------------------更新----------------------
想通了,这里面涉及到了对进制的理解
一个D进制数,到M进制
D%M=D->M 的末位数//-> 转到
D/M=D->M   去掉一个末位数剩下的M
编辑于 2017-06-11 11:23:21 回复(0)
#include<stdio.h>
#include<iostream>
using namespace std;
charb[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
inta[32];
intconv(intn,intr)
{
    intlen=0,i=0,sum=0;
    while(n)
    {
        a[len]=n%r;
        n/=r;
        if(a[len++]==1)sum++;
    }      
    returnsum;
}
intmain()
{
    intn,r;
    while(cin>>n>>r)
    {
        cout<<conv(n,r)<<endl;
    }
    return0;
}

发表于 2017-05-13 11:21:05 回复(0)
#include <iostream>
using namespace std;
int main()
{		
	int num, cnt;
	while (cin >> num >> cnt)
	{
		if (num == 1)
		{
			cout << 1 << endl;
			continue;
		}
		int count = 0;
		while (num)
		{
			if (num%cnt == 1)
				count++;
			num /= cnt;
		}
		cout << count << endl;
	}
	return 0;
}

发表于 2017-04-19 20:37:41 回复(0)
我的代码在本机是答案是正确的,但提交到OJ上提示答案错误,具体为:
测试用例:
1 2
对应输出应该为:
1
你的输出为:
16
然而在我机器上的输出也是1。
运行截图

具体代码为:
#include<stdio.h>
int main(){
	long n;
	int r;
	while(scanf("%d %d",&n,&r)!=EOF){
		int cnt=0;
		do{
			if(n%r==1)cnt++;
			n/=r;
		}while(n);
		printf("%d\n",cnt);
	}
	return 0;
}
发表于 2016-02-25 19:47:27 回复(3)