美文网首页程序员
枚举算法作业(五)

枚举算法作业(五)

作者: 续袁 | 来源:发表于2018-09-25 19:44 被阅读116次

时间限制 1000 ms
内存限制 64 MB
题目描述
李老师的lucky number 是3,5和7,他爱屋及乌,还把所有质因数只有3,5,7的数字认定为lucky number,比如9, 15, 21, 25等等。请聪明的你帮忙算一算小于等于x的lucky number有多少个?

输入数据
一个正整数x,3=<x<=1000000000000

输出数据
小于等于x的lucky number的个数。

样例输入
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;
}

相关文章

  • 枚举算法作业(五)

    时间限制 1000 ms内存限制 64 MB题目描述李老师的lucky number 是3,5和7,他爱屋及乌,还...

  • 枚举算法作业(四)

    时间限制 1000 ms内存限制 64 MB题目描述我们有n根的木棍。现在从这些木棍中切割出来m条长度相同的木棍,...

  • 枚举算法作业(一)

    时间限制 1000 ms内存限制 64 MB题目描述有一条河,河中间有一些石头,已知石头的数量和相邻两块石头之间的...

  • 枚举算法作业(三)

    时间限制 1000 ms内存限制 64 MB题目描述给你一个长度为n的数组和一个正整数k,问从数组中任选两个数使其...

  • 枚举算法作业(六)

    时间限制 1000 ms内存限制 64 MB题目描述如果一个质数能被表示为三个不同的质数的和的形式,那么我们称它为...

  • 枚举算法作业(二)

    时间限制 1000 ms内存限制 64 MB题目描述李老师正准备暑假旅行,他有一个容量为L的行李箱和n个物品(n不...

  • 算法学习3_枚举

    枚举算法又称穷举算法枚举算法的核心思想 : 有序的尝试每一种可能 题一、 3 * 6528 = 3 * 8256 ...

  • 算法 | 枚举算法

    【算法思想】 利用计算机运算速度快的特点,对问题的所有可能答案一一列举,并逐一检验,符合条件的保留,不符合的丢弃。...

  • 2018-08-02

    php实现组合枚举算法 源码

  • 枚举算法

    枚举法:又称穷举法,是指从可能的集合中一一列举各个元素,用题目给定的约束条件判定哪些是无用的,哪些是有用的。能使命...

网友评论

    本文标题:枚举算法作业(五)

    本文链接:https://www.haomeiwen.com/subject/lglxoftx.html