#coding:utf-8 from collections import defaultdict import codecs from math import log
classTrie(object): classTrieNode(): def__init__(self): self.value = 0 self.trans = {} def__init__(self): self.root = self.TrieNode() defadd(self, word, value=1): cur = self.root for ch in word: try: cur = cur.trans[ch] except: cur.trans[ch] = self.TrieNode() cur = cur.trans[ch] cur.value = value def_walk(self, node, ch): if ch in node.trans: node = node.trans[ch] return node, node.value else: returnNone, 0 defmatch_all(self, s): ret = [] cur = self.root for ch in s: cur, value = self._walk(cur, ch) ifnot cur: break if value: ret.append(value) return ret
from pagedown.widgets import AdminPagedownWidget from django import forms from blog.models import Post
classPostForm(forms.ModelForm): content = forms.CharField(widget=AdminPagedownWidget()) classMeta: model = Post
这里是将content字段设置为markdown编辑,之后在admin.py中添加如下内容:
1 2 3 4 5 6
from django.contrib import admin from blog.models import Post from blog.forms import PostForm class PostAdmin(admin.ModelAdmin): form = PostForm admin.site.register(Post, PostAdmin)
defpone(p, u): c = 0 for x in xrange(2, int(sqrt(p)) + 1): if p % x == 0and x + p / x < u: c += 1 return c >= 2
defsone(s, u): for x in xrange(2, s / 2): y = s - x ifnot pone(x * y, u): returnFalse returnTrue
defptwo(p, u): c = 0 for x in xrange(2, int(sqrt(p)) + 1): if p % x == 0and x + p / x < u: y = p / x if sone(x + y, u): c += 1 return c == 1 defstwo(s, u): c = 0 for x in xrange(2, s / 2): y = s - x if ptwo(x * y, u): c += 1 return c == 1
if __name__ == "__main__": u = 100 for x in xrange(2, u / 2): for y in xrange(x + 1, u - x): p = x * y s = x + y if pone(p, u) and sone(s, u) and ptwo(p, u) and stwo(s, u): print"x:%d, y:%d, p:%d, s:%d " % (x, y, p, s)