URAL 1385 Interesting Number
来源:互联网 发布:2016无限申请淘宝小号 编辑:程序博客网 时间:2024/05/16 12:59
Description
Tyomitch calls the number with 2 N digits (without leading zeroes) "interesting", if it's divisible by both the number formed from its firstN digits and the number formed from its last N digits. For example, 1020 is "interesting" (divisible by 10 and 20) and 2005 is not. Tyomitch wants to know how many "interesting" 2 N-digit numbers exist. You are to help him.
Input
Input contains an integer N (1 ≤ N ≤ 10000).
Output
Output the number of "interesting" 2 N-digit numbers.
Sample Input
1
14
Notes
11, 12, 15, 22, 24, 33, 36, 44, 48, 55, 66, 77, 88, 99.
脑洞题。。打表可以看出来大致的规律。
还有一种方法
把这个数写成 a*10^n+b,则满足条件等价于b%a=0 and a*10^n%b=0,令 b=ka,则10^n%c=0。且a和b都是n位数。
当 n==1 c可为 1 2 5;当 n==2 c可为 1 2 4 5;n>=3 c可为1 2 4 5 8.
当a为n位数时,要控制a的范围保证b也是n位数。显然,n==1 ans=14,n==2 ans=155
n>=3时,令 a = 10^(n+1)
则(a/8-a/10)*5+(a/5-a/8)*4+(a/4-a/5)*3+(a/2-a/4)*2+(a-a/2)*5=63/40*(10^n)
#include <iostream>#include <stdio.h>#include <string>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int n;int main(){ while(~scanf("%d",&n)) { if(n==1) cout<<14<<endl; else if(n==2) cout<<155<<endl; else { cout<<1575; for(int i=0;i<n-3;i++) cout<<0; cout<<endl; } } return 0;}
0 0
- URAL 1385 Interesting Number
- URAL 1385 Interesting Number
- URAL 1385 Interesting Number 解题报告
- URAL 1385 Interesting Number (暴力打表 + 找规律)
- ural 2070 - Interesting Numbers
- URAL 2070 Interesting Numbers
- Ural 2070 Interesting Numbers
- Interesting Numbers URAL
- Scarily interesting! (URAL
- URAL 2070 Interesting Numbers(数学)
- URAL 2021 Scarily interesting!(贪心)
- URAL 2024 Adventure Time 思维题、Interesting
- URAL 2070 Interesting Numbers(数学)
- URAL 2070 Interesting Numbers (素数枚举)
- 素数标记 Interesting Numbers URAL - 2070
- URAL 2070 Interesting Numbers(数论)
- ural 2070 Interesting Numbers(数论基础)
- Interesting way to validate number
- More is better
- Balanced Binary Tree
- 各种距离汇总
- ObjC的initialize和init
- 蓝桥杯 算法训练 出现次数最多的整数
- URAL 1385 Interesting Number
- JAVA 枚举类型
- C++中new和delete用法
- RatingBar简单介绍
- iOS新浪微博客户端开发(4)——自定义微博Cell的实现
- 【MOOC】程序设计入门-C 语言 作业汇总
- 第二周阅读程序(1)
- 当ListView有Header时,onItemClick里的position不正确
- 把数组排成最小数