摘要:
美素数Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识。 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数。 给定一个区间,你能计算出这个区间内有多少个美素数吗?Input第一行输入一个正整数T,表示总共有T组数据(T 2 #include 3 4 #define maxn 1000005 5 6 int prime[maxn], ans[maxn]; 7 8 void is_prime() ... 阅读全文
摘要:
又见GCDDescription有三个正整数a,b,c(0 2 3 int gcd(int m, int n) 4 { 5 int t; 6 if (m < n) 7 { 8 t = m; 9 m = n;10 n = t;11 }12 while (m % n != 0)13 {14 t = m % n;15 m = n;16 n = t;17 }18 return n;19 }20 21 int main()22 {23 ... 阅读全文
摘要:
Jeff and PeriodsDescriptionOne day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:x occurs in sequence a.Consider all positions of numbers x in the sequ 阅读全文