实现效果: 知识运用: Math类的Pow方法:返回指定数字的指定次幂 public static double Pow(double x,double y) 实现代码: public string sum(int num) { string result = ""; double sum = 0; for (int i = 1; i <= num;i++ ) { sum += Math.Pow(i,i); result += i + "的" + i + &q
两种循环: 1 for in 2 while #coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 循环语句 """ '''for in''' #打印0-9 for i in range(10): print(i) #取出元组中不能被2整除的数据 turple = (1,13,33,54,8329) for i in turple: if(i%2 == 1): print(i) '''w
问题:求列表中每个元素的元素次方之和>>> a=[1,2,3,4]>>> k=len(a)第一种解法# s=0# for x in a:# s+=x**k第二种解法列表解析,每个元素的元素数次方>>> [x**k for x in a][1, 16, 81, 256] 求列表元素之和>>> sum([x**k for x in a])354 水仙花数 一.先在python交互式中寻找算法>>>
Quite Good Numbers Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 77, Accepted users: 57 Problem 12876 : No special judgement Problem description A "perfect" number is an integer that is equal to the sum
E - The Boss on Mars Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4059 Description On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss. Due