時(shí)間限制 1000 ms
內(nèi)存限制 64 MB
題目描述
李老師的lucky number 是3,5和7,他愛屋及烏,還把所有質(zhì)因數(shù)只有3,5,7的數(shù)字認(rèn)定為lucky number,比如9, 15, 21, 25等等。請(qǐng)聰明的你幫忙算一算小于等于x的lucky number有多少個(gè)?
輸入數(shù)據(jù)
一個(gè)正整數(shù)x,3=<x<=1000000000000
輸出數(shù)據(jù)
小于等于x的lucky number的個(gè)數(shù)。
樣例輸入
49
樣例輸出
11
樣例說明
int存不下
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include "stdlib.h"
#include <iostream>
using namespace std;
int main(){
long x;
long count = 0;
cin >> x;
for (long i = 0; i < x / 3+1; i++)
for (long j = 0; j < x / 5+1; j++)
for (long k = 0; k < x / 7+1; k++){
if ((pow(3, i)* pow(5, j) * pow(7, k) <= x)&&(i+j+k)>0) {
count = count + 1;
//cout << "i:" << i << " j:" << j << " k:" << k << endl;
}
}
cout << count << endl;
return 0;
}
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include "stdlib.h"
#include <iostream>
using namespace std;
long rooting(long x, int a);
int main(){
long x;
long count = 0;
cin >> x;
long three_times =rooting(x,3);
long five_times = rooting(x, 5);
long seven_times = rooting(x,7);
//count = three_times + five_times + seven_times;
for (long i = 0; i <three_times + 1; i++)
for (long j = 0; j < five_times + 1; j++)
for (long k = 0; k < seven_times + 1; k++){
if ((pow(3, i)* pow(5, j) * pow(7, k) <= x) && (i + j + k)>0) {
count = count + 1;
//cout << "i:" << i << " j:" << j << " k:" << k << endl;
}
}
cout << count << endl;
return 0;
}
long rooting(long x, int a){
int three_m = x % a;
x = x - three_m;
long times = 0;
while (x > 1){
x = x / a;
times = times + 1;
}
return times;
}