SGU 169 numbers 数学
For example, P(1243)=1*2*4*3=24; P(198501243)=0.
Let us call n to be a good number, if (p(n)<>0) and (n mod P(n)=0).
Let us call n to be a perfect number, if both n and n+1 are good numbers.
You are to write a program, which, given the number K, counts all such
numbers n that n is perfect and n contains exactly K digits in decimal notation.
题意:一道很有意思的题,规律是通过计算,得到k位数除个位数之外,所有的非个位数都为1,所以只需看最后一位的情况与前面组成的数能构成多少perfect number
假设n的各个位数为a1,a2···ak,那么n+1的各个位数为a1,a2···ak+1
因为要求n mod P(n)=0,所以有n=s1*a1*a2···*ak,n+1=s2*a1*a2···*(ak+1)
在此处s1与s2因为n mod P(n)=0所以肯定是整数(因为n一定是P(n)的m倍),所以有1=[s2*(ak+1)-s1*ak]*a1*a2···ak-1
由此可得出a1,a2···肯定为1
设个位数为x
x=1, perfect numbers
x=2, 当6|(k-1)时是perfect numbers
x=3,不是
x=4,不是
x=5,当3|(k-1)时是perfect numbers
x=6,当6|(k-1)时是perfect numbers
x=7,不是
x=8,不是
代码:
#include"bits/stdc++.h"
using namespace std;
int k;
int main()
{
while(scanf("%d",&k)!=EOF)
{
k--;
int ans=;
if(!k) puts("");
else
{
if(k%==) ans+=;
if(k%==) ans++;
pi(ans);
}
}
return ;
}
SGU 169 numbers 数学的更多相关文章
- sgu 169 Numbers
题意:n和n+1同时被数位乘积整除的k位数个数. 假如a是237,b是238.由于个位以前的数一样.那么对于2,如果a%2==0,b%2就!=0,如果a%3==0,b%3就!=0.因此个位以前的数只能 ...
- SGU 169 Numbers (找规律)
题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1 ...
- UVA 11582 Colossal Fibonacci Numbers(数学)
Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- HDU 6659 Acesrc and Good Numbers (数学 思维)
2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...
- UVA 11481 - Arrange the Numbers 数学
Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You ca ...
- POJ2402/UVA 12050 Palindrome Numbers 数学思维
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
- CF385C Bear and Prime Numbers 数学
题意翻译 给你一串数列a.对于一个质数p,定义函数f(p)=a数列中能被p整除的数的个数.给出m组询问l,r,询问[l,r]区间内所有素数p的f(p)之和. 题目描述 Recently, the be ...
- Poj 1338 Ugly Numbers(数学推导)
一.题目大意 本题要求写出前1500个仅能被2,3,5整除的数. 二.题解 最初的想法是从1开始检验该数是否只能被2,3,5整除,方法是这样的,对于一个数,如果它能被2整除,就除以2,如果它能被3整除 ...
随机推荐
- Redis入门--(二)Redis的概述
1.Redis的由来 创始人觉得Mysql不好用,就自己写了: 国内使用Redis的网站有新浪微博,知乎: 国外GitHub: VMWare也支持redis的开发 2.Redis的概述 官方提供的测试 ...
- apache管理命令
常用的 httpd.exe -k [install(安装).uninstall(卸载).start(启动).stop(停止).restart(重启)] 说明:要执行命令,需进入到apache安装目录/ ...
- Windows环境下sublime text 3搭建前端开发环境
一.安装SubLime Text 3 SubLime Text 3官网下载:https://www.sublimetext.com/ 二.安装Package Control 进入sublime后,按快 ...
- The fifth day
All men cannot be first . 今日单词: first(形容词):第一的:基本的:最早的:(副词):第一:首先 翻译:不可能人人都是第一名. <Only Love>-- ...
- Android打包异常
Android在打包的时候,报错: 找不到类,或者打包之后运行找不到类,都可以在混淆文件中添加这个属性: -dontoptimize 通过测试,都可以解决. 来自为知笔记(Wiz)
- Laravel 获取当前 Guard 分析 —源自电商购物车的实际需求
iBrand 产品中关于购物车的需求比较复杂,我们基于 overture/laravel-shopping-cart 扩展出了更加符合电商需求的购物车包,之前有文章进行过简单的介绍: Laravel ...
- Python基础学习之序列(2)
通用序列操作 所有序列类型都可以进行某些特定的操作.这些操作包括:索引(indexing).分片(sliceing).加(adding).乖(multiplying)以及检查某个元素是否属于序列的成员 ...
- 思科双出口+策略路由+NAT
使用策略路由,从教育网出去的,在教育网接口进行nat转换 访问教育网资源平时走教育网,故障走电信 访问internat走电信线路,故障走教育网 服务器静态绑定教育网ip,不管电信.联通.教育网都走教育 ...
- phpStudy-在使用phpMyAdmin报404Error
今天刚刚知道什么是phpStudy和phpMyAdmin,感觉还可以吧.熬到凌晨两点多就为看这点东西.结果不知道怎么回事,当我在网上转一圈回来后发现自己的数据管理器竟然进不进去了! 神马情况啊?我的解 ...
- IOS 多线程-pthread
#import <pthread.h> @interface HMViewController () - (IBAction)btnClick; @end @implementation ...