[CodeForces] [630C] Lucky Numbers

Problem Description

Loading...

Problem Analysis

lucky numbers
i.e. numbers that contain only 7 or 8

Asked how many lucky numbers there are with no more than n digits
A combinatorics problem

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include<stdio.h>
#include<math.h>
int main() {
	long long a[60]= {0};
	for(int i=1; i<56; i++)
		a[i]=pow(2,i)+a[i-1];
	int n;
	while(scanf("%d",&n)!=EOF) {
		printf("%lld\n",a[n]);
	}
	return 0;
}

Problem link: 【CodeForces】[630C]Lucky Numbers

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...