1 问题描述

Problem Description

  We call a number interesting, if and only if:

  1. Its digits consists of only 0, 1, 2 and 3, and all these digits occurred at least once.

  2. Inside this number, all 0s occur before any 1s, and all 2s occur before any 3s.

  Therefore, the smallest interesting number according to our definition is 2013. There are two more interseting number of 4 digits: 2031 and 2301.

  Your task is to calculate the number of interesting numbers of exactly n digits. As the answer might be very large, you only need to output the answer modulo 1000000007.

Input Format

  The input has one line consisting of one positive integer n (4 ≤ n ≤ 10^15).

Output Format

  The output has just one line, containing the number of interesting numbers of exactly n digits, modulo 1000000007.

Input Sample

  4

Output Sample

  3

2 解决方案

本题主要考查数学组合数推理化简,具体思考过程如下:



推导过程,在草稿纸上推导了一下:

import java.util.Scanner;

public class Main {
static long n;
static long mul, ans, res;
static long monum = 1000000007; private static long cal(long n) {
if (n == 1)
return 2;
long num = cal(n / 2);
num = num * num % monum;
if (n % 2 == 1)
num = num * 2 % monum;
return num;
} public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in);
n = reader.nextLong();
if (n == 4)
System.out.println(3);
else {
n = n - 1;
res = (n % monum) * (n % monum);
res = ((res - 3 * n) % monum + monum) % monum;
n = n - 2;
mul = cal(n);
res = res * mul % monum;
n = n + 2;
res = (res + n) % monum;
System.out.println(res);
}
} }

java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版的更多相关文章

  1. 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...

  2. Java实现 蓝桥杯 算法提高 进攻策略加强(暴力)

    试题 算法提高 进攻策略加强 问题描述 植物大战僵尸这款游戏中,还有一个特别的玩儿法:玩家操纵僵尸进攻植物. 首先,僵尸有m种(每种僵尸都是无限多的),玩家可以选择合适的僵尸来进攻.使用第i种僵尸需要 ...

  3. Java实现 蓝桥杯 算法提高 小X的购物计划

    试题 算法提高 小X的购物计划 问题描述 小X打算去超市shopping.小X没什么钱,只有N元.超市里有M种物品,每种物品都需要money,在小X心中有一个重要度.有的物品有无限件,有的物品只有几件 ...

  4. Java实现 蓝桥杯 算法提高 天天向上(DP)

    试题 算法提高 天天向上 问题描述 A同学的学习成绩十分不稳定,于是老师对他说:"只要你连续4天成绩有进步,那我就奖励给你一朵小红花."可是这对于A同学太困难了.于是,老师对他放宽 ...

  5. Java实现 蓝桥杯 算法提高 欧拉函数(数学)

    试题 算法提高 欧拉函数 问题描述 老师出了一道难题,小酱不会做,请你编个程序帮帮他,奖金一瓶酱油: 从1-n中有多少个数与n互质? |||||╭══╮ ┌═════┐ ╭╯让路║═║酱油专用车║ ╰ ...

  6. Java实现 蓝桥杯 算法提高 计算超阶乘(暴力)

    试题 算法提高 计算超阶乘 问题描述 计算1*(1+k)(1+2k)(1+3k)-(1+n*k-k)的末尾有多少个0,最后一位非0位是多少. 输入格式 输入的第一行包含两个整数n, k. 输出格式 输 ...

  7. Java实现蓝桥杯 算法提高 线段和点

    算法提高 线段和点 时间限制:1.0s 内存限制:256.0MB 提交此题 问题描述 有n个点和m个区间,点和区间的端点全部是整数,对于点a和区间[b,c],若a>=b且a<=c,称点a满 ...

  8. Java实现蓝桥杯-算法提高 P1003

    算法提高 P1003 时间限制:1.0s 内存限制:256.0MB 作为一名网络警察,你的任务是监视电子邮件,看其中是否有一些敏感的关键词.不过,有些狡猾的犯罪嫌疑人会改变某些单词的字母顺序,以逃避检 ...

  9. Java实现蓝桥杯 算法提高 八皇后 改

    **算法提高 8皇后·改** 时间限制:1.0s 内存限制:256.0MB 提交此题 问题描述 规则同8皇后问题,但是棋盘上每格都有一个数字,要求八皇后所在格子数字之和最大. 输入格式 一个8*8的棋 ...

随机推荐

  1. Mysql 常用函数(7)- length 函数

    Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html length 的作用 返回字符串的字节长度 注意: ...

  2. 【基准测试】BenchmarkDotNet介绍

    BenchmarkDotNet 概述 BenchmarkDotNet helps you to transform methods into benchmarks, track their perfo ...

  3. 常见的DOS命令总结

    常用的内部命令有MD.CD.RD.DIR.PATH.COPY.TYPE.EDIT.REN.DEL.CLS.VER.DATE.TIME.PROMPT. 常用的外部命令有DELTREE.FORMAT.DI ...

  4. 小程序externalClasses介绍

    小程序externalClasses 1.介绍:我们在封装组件的时候,有时候需要对外暴露出class,可以由调用者来决定组件中一部分的样式,此时就需要使用它了 // components/dong/i ...

  5. 微信小程序中,如何阻止多次点击单击事件

    在微信小程序中,有自制对话框用于提交数据,但是会出现用户连续点击,多次提交数据的情况. //.wxml <view class="acertain" bindtap=&quo ...

  6. Interactive and non-interactive shell环境变量的差异

    背景 在mac上安装mosh server后,用mosh client去连接,一直报command not found的错 zsh: command not found: mosh-server 但是 ...

  7. JS的函数和对象四

    复习 数组 toString/join/concat/slice/splice/reverse/sort/ push/pop/unshift/shift 字符串 new String(2)  /  S ...

  8. NodeJS的概述

    1.NodeJS概述 基于谷歌V8引擎,运行在服务器端的环境 对比JS和NodeJS (1)JS运行在浏览器端,存在多种浏览器解释器,容易产生兼容性的问题:而NodeJS运行在服务器端,只有V8引擎一 ...

  9. Redis-主从

    主从复制过程 1.从服务器开始连接主服务器时,会向主服务器发送一个SYNC同步命令 2.主服务器接收到命令后,执行BGSAVE,异步的将写命令保存到一个缓冲区里 3.主服务器执行完BGSAVE之后,就 ...

  10. Vue的双向绑定原理

    Vue的构造函数分析 vm就是MVVM中的View Model var vm = new Vue({ el: '#app', data: { message: 'Hello Vue!' } }) /* ...