。。。。本来博主想一心一意搞算法和C++的,但今天的大数用C++写真的。。。心态爆炸,然后学了一波python。。。多路周折终于A了这题

python的语言在有了c语言的基础上其实还挺好学的。。。虽然博主学了半个下午才把线性素数筛和gcd写出来了QAQ,但博主觉得各位应该更快。。。。

python不需要头文件。。。直接写,变量也不用定义但它的读入有点。。。一行只读一个东西

n=int(input())

这个有点类似于scanf ("%d",&n),但,python的这个n好像没有大小范围限制。。。前面的int是将输入的东西强转成int型(这个int是理论无限大的)python的读入是一个字符串,所以需要这样写,以下是两种写法:

a=input()
b=input()
c=a+b
c=int(a)+int(b)

输入:

123

456

前面的c的值是123456,后面的值是579

print的话是输出,print(n)就是将n输出,只不过这个是换行的,如果想不换行的话:print(n,end=" ")就是将结束符换成空格

接下来就是循环了:

for i in range(a,b):......

很好理解,就不多说了,有一点需要注意的是它不会到b,他是到b-1的。。

while a>=b or xx:......

接下来就是判断了

if aa:......
elif ax>3:......
else :...

。。。这个有点意思,else if 变成了elif。。

下面就是数组了,这个有点鬼畜了,博主现在只会一维数组QAQ。

a=[1,2,3]

这个数组什么都可以存。。。。一样从0开始,现在它只有3的大小,下标到2,我们可以先初始化它将它的空间扩大:

for i in range(3,100000):a.append(..)

a.append()就是将括号里的东西插入a里面,有点类似于C++里面的vector。

下面就是除法了。。。这个除法有点骚,int/int变成了浮点型,我今天就是因为这个一直WA3,会有浮点误差,如果确定是整除的话使用//就好了

下面写一个素数筛:

vis=[]
mac=int(1e5+10)
for i in range (0,mac):vis.append(0)
m=int(100010 ** 0.5)
for i in range(2,m):if (vis[i]==0):j=i*iwhile j<mac-5:vis[j]=1;j+=i;
prim=[]
for i in range(2,mac-5):if vis[i]==0:prim.append(i)

接下来len(prim)的大小就是prim的大小,如果C语言懂了素数筛了的话应该很容易懂了

接下来就是一个函数的定义和运用,其实和C语言也是一样的:

#def hhh(a):......

定义一个hhh的函数,里面传进来几个变量。。。然后就开始在这个函数里面xjb搞就好了

下面给出gcd函数:

def gcd(a,b):if b:return gcd(b,a%b)return a

下面就给出今天大数自闭的一题吧,也是博主的第一个python比较成熟一些的程序吧:

Resistors in Parallel

Time limit

2000 ms

Memory limit

1048576 kB

In this physics problem, what we are concerned about are only resistors. If you are poor at physics, do not worry, since solving this problem does not require you to have advanced abilities in physics.

Resistors are said to be connected together in parallel when both of their terminals are respectively connected to each terminal of the other resistors.

We have the following parallel resistor equation for k resistors with resistances R1, R2, ..., Rk in parallel and their combined resistance R:

Now you have n resistors, the i-th of which has a resistance of ri ohms with the equation

You also have n selections, the i-th of which is a set of resistors Si such that

Please find a selection in which the resistors form a parallel resistor with the minimum resistance and output the reduced fraction  of its resistance.

Input

The input contains several test cases, and the first line contains a positive integer T indicating the number of test cases which is up to 100.

For each test case, the only one line contains an integer n, where 1 ≤ n ≤ 10100.

Output

For each test case, output a line containing a reduced fraction of the form p/qindicating the minimum possible resistance, where p and q should be positive numbers that are coprime.

Example

Input

3
10
100
1000

Output

1/2
5/12
35/96

题目大意是给你n个集合,每个集合的电阻的大小是它的因子,当他的大小可以被一个平方数整除时该电阻为无穷大,比如4,8的电阻就是无穷大的。让你求这些集合中最小的并联电阻,比如2的电阻是1/(1/1+1/2)=2/3

这题就是打个表找规律就行了。最后会发现,分子就是素数之乘积,分母就是素数+1的乘积,然后用gcd约分一下就好了

以下是AC代码:

vis=[]
mac=int(1e5+10)
for i in range (0,mac):vis.append(0)
m=int(100010 ** 0.5)
for i in range(2,m):if (vis[i]==0):j=i*iwhile j<mac-5:vis[j]=1;j+=i;
prim=[]
for i in range(2,mac-5):if vis[i]==0:prim.append(i)  def gcd(a,b):if b:return gcd(b,a%b)return at=int(input())
for o in range(1,t+1):n=int(input())j=0;fenmu=1;fenzi=1while fenzi*prim[j]<=n:fenzi*=prim[j]fenmu*=(prim[j]+1)j+=1gdx=gcd(fenzi,fenmu)fenzi=fenzi//gdxfenmu=fenmu//gdxprint(fenzi,end="")print("/",end="")print(fenmu)

python笔记之1-简单读入+循环、判断+数组+函数调用+题目Resistors in Parallel(18焦作)相关推荐

  1. Java循环判断数组中是否包含字符串

    关于Java循环判断数组中是否包含字符串的方法: // 循环判断数组中是否包含字符串public static boolean useLoop(String[] arr, String targetV ...

  2. python笔记-05(条件、循环及其他语句)

    1.再谈print语句 print('name:', 'tom') # 将会在name和tom中间插入一个空格 print('name',',','tome') # 在name和tom之间添加逗号 p ...

  3. python笔记之while和for循环练习

    实例1 输入n个数,求每次输入后的算术平均数. sum = 0 #总和 count = 0 #计数 while True:n = input("请输入一个数:")if n == & ...

  4. Python学习笔记(二):循环

    http://www.w3cschool.cc/python/python-while-loop.html 1.Python While循环语句 Python 编程中 while 语句用于循环执行程序 ...

  5. python for循环连续输入五个成绩判断等级_Python条件循环判断

    1.条件判断语句 Python中条件选择语句的关键字为:if .elif .else这三个.其基本形式如下: 1 2 3 4 5 6 7 8 9 age_of_cc= 27 age= int(inpu ...

  6. python怎么用for循环找出最大值_如何获取Python简单for循环索引

    如何获取Python简单for循环索引 这篇文章主要介绍了如何获取Python简单for循环索引,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Py ...

  7. Python学习笔记——条件分支和while循环

    目录 Python的比较操作符 Python的逻辑操作符 Python的条件分支语法 Python的while循环语法 Python的三元表达式 Python的比较操作符 > 大于 >= ...

  8. tkinter message_【莫烦Python】Tkinter 做简单的窗口视窗lt;学习笔记(2)gt;

    接(1) 还有五个苹果:[莫烦Python]Tkinter 做简单的窗口视窗<学习笔记>​zhuanlan.zhihu.com 登录窗口小例子(pickle存取) import

  9. Python学习笔记D2(条件与循环)

    Python学习笔记D2(条件与循环) 条件语句 if expression:(可以利用布尔操作符and,or,not) *****语句- elif:(else if) ***** 语句- else: ...

最新文章

  1. 虚拟机网络设置方法——转载
  2. NETCF平台下利用XmlSerializer对于复杂类型序列化的探索(三)
  3. 从技术角度谈一谈,我参与设计开发的手Q春节红包项目--转
  4. [No00009D]使用visual studio 2015 update3打包程序安装包的简单方法(不需要InstallShield)...
  5. 移除元素--双指针法
  6. Vue.js 2.0从入门到放弃---入门实例(二)
  7. Atitit json序列化工具 JsonParserAtiver 参考 Atitit json序列化原理 序列化是将一个对象变成json格式的字符串,而反序列化是将json格式的字符串变
  8. windows如何在局域网下共享文件(传输文件、修改文件)
  9. GitHub上收录400余篇任正非的讲话稿
  10. 阿里云ECS上使用docker搭建filebeat+kafka集群+zookeep集群+logstash+elasticsearch集群+kibana实现跨主机日志收集系统【四】
  11. python字符串的内部函数_「Python」字符串操作内置函数
  12. TTL反相器、OC门、TS门、推挽输出、开漏输出
  13. 英语论文写作词汇积累20161101
  14. 那个学php的上吊了,这位一路名校的中国博士,突然在美国上吊自杀了
  15. Linux系统换清华源
  16. 光纤分类——多模和单模
  17. 《追风筝的人》观后感
  18. 博文收藏,便于后续查找
  19. python获取职位信息
  20. Object.keys方法详解

热门文章

  1. 程序物语(七):项目经理预成长
  2. 机器学习实战——K均值
  3. 优化方法——罚函数法
  4. 如何设计一个高并发的存储系统
  5. 浅谈卡尔曼滤波(Kalman Filter)(一)
  6. NDCG评价指标讲解
  7. Java入门学习(九)
  8. AJAX获取数据然后显示在页面
  9. Linux下Subclipse的JavaHL
  10. upc 6617: Finite Encyclopedia of Integer Sequences(树的先序遍历第n/2个结点)