Project Euler #80: Square root digital expansion
from decimal import getcontext, Decimal def main():
n = int(raw_input())
p = int(raw_input()) getcontext().prec = p+10 # 扩大精度,保证接过
sum = 0 for i in range(1,n+1):
nTemp = Decimal(i).sqrt()
if nTemp._isinteger() : # 自生函数的判断
sum += 0
else:
nTemp = str(nTemp)
for _ in range(p+1): # 空下来一个.,所以+1
if nTemp[_] != '.':
sum += int(nTemp[_]) print sum main()
学习
抽象化理解题目
边界值问题
错误
读题不仔细
Link:
https://www.hackerrank.com/contests/projecteuler/challenges/euler080
Project Euler #80: Square root digital expansion的更多相关文章
- Project Euler 80:Square root digital expansion 平方根数字展开
Square root digital expansion It is well known that if the square root of a natural number is not an ...
- Project Euler 57: Square root convergents
五十七.平方根收敛(Square root convergents) 二的平方根可以表示为以下这个无穷连分数: \[ \sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac ...
- Project Euler 92:Square digit chains C++
A number chain is created by continuously adding the square of the digits in a number to form a new ...
- Project Euler 59: XOR decryption
计算机上的每个字母都对应一个独特的编号,普遍接受的标准是ASCII(美国信息交换标准代码).例如,大写字母的A的ASCII码是65,星号(*)的ASCII码是42,而小写字母k的代码是107. 一种现 ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Codeforces 715A. Plus and Square Root[数学构造]
A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- cf B. Hungry Sequence
http://codeforces.com/contest/327/problem/B 这道题素数打表就行. #include <cstdio> #include <cstring& ...
- Codeforces 461B Appleman and Tree
http://codeforces.com/problemset/problem/461/B 思路:dp,dp[i][0]代表这个联通块没有黑点的方案数,dp[i][1]代表有一个黑点的方案数 转移: ...
- RedisTemplate
Spring Boot中Jedis几个api返回值的确认 @RequestMapping("/del/{key}") public String del(@PathVariable ...
- js深入研究之函数内的函数
第一种 function foo() { ; function bar() { a *= ; } bar(); return a; } 第二种 function foo() { ; function ...
- XSS初体验
主要内容 什么是XSS? XSS的危害有哪些? 常见的XSS漏洞 如何防范XSS? 什么是XSS? 跨站脚本攻击(Cross Site Scripting),是一种 Web 应用程序的漏洞,当来自 ...
- ibatis学习之道:ibatis的<[CDATA]>dynamic属性跟#$的应用
ibatis的<![CDATA]>,dynamic属性和#,$的应用 <![CDATA[ ]]>的正确使用 ibatis作为一种半自动化的OR Mapping工具,其灵活性 ...
- c语言指针与结构体
#include <stdio.h> #include <stdlib.h> struct mydata { int num; ]; }; void main1() { /*i ...
- Arcgis API for Android之GPS定位
欢迎大家增加Arcgis API for Android的QQ交流群:337469080 先说说写这篇文章的原因吧,在群内讨论的过程中,有人提到了定位的问题,刚好,自己曾经在做相关工作的时候做过相关的 ...
- c++ 11 多线程教学(1)
本篇教学代码可在GitHub获得:https://github.com/sol-prog/threads. 在之前的教学中,我展示了一些最新进的C++11语言内容: 1. 正则表达式(http://s ...
- android 开发随笔 - 开发环境搭建
1.1 问题: 'tools.jar' seems to be not in Android Studio classpath. Please ensure JAVA_HOME points to J ...