数据结构之ZOJ——Exploding CPU

Problem Description
The well known hardware manufacturing company Processors for Professors is about to release a highly specialized CPU with exceptional functionality in, amongst other areas, number theory. It has, for example, an instruction PFACT that takes one parameter and returns all prime factors of that parameter, with an outstanding execution speed. It has, however, one considerable problem. The scientists at the testing lab has just found out that the PFACT instruction for some special input values freaks out and makes the entire processor explode. Even though this could be an amusing effect, it is not the way it was intended to work. The skilled mathematicians have, by trial and error, found that the explosive numbers all share the same interesting number theoretic properties, which might be of help when troubleshooting.

An explosive number is a number where all s are distinct prime numbers such that . A and B are always integers, and might be different for different explosive numbers.

For example, the processor will explode when factorizing the number 4505, because 4505 = 1*5*17*53 and 5 = 3*1+2, 17 = 3*5+2 and 53 = 3*17+2 and the numbers 5, 17 and 53 are all prime numbers. In this case A = 3 and B = 2.

You are kindly asked to write a computer program that will aid this company in estimating the impact of the errors, by calculating the amount of explosive numbers that exists within a given range of integers.

Input
The input starts with a row containing the number 0 <= N <= 100 of test cases that will follow. For each test case, there will be one row containing two integers, separated by a single space. These numbers are such that .

Output
For each test case, output the number of explosive numbers that exist in
the range .

Sample Input
2
4505 4505
0 5000

Sample Output
1
5

0
o645540557
o645540557 ??
8 个月之前 回复

1个回答

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Exploding CPU
Problem DescriptionnThe well known hardware manufacturing company Processors for Professors is about to release a highly specialized CPU with exceptional functionality in, amongst other areas, number theory. It has, for example, an instruction PFACT that takes one parameter and returns all prime factors of that parameter, with an outstanding execution speed. It has, however, one considerable problem. The scientists at the testing lab has just found out that the PFACT instruction for some special input values freaks out and makes the entire processor explode. Even though this could be an amusing effect, it is not the way it was intended to work. The skilled mathematicians have, by trial and error, found that the explosive numbers all share the same interesting number theoretic properties, which might be of help when troubleshooting.nnAn explosive number is a number where all s are distinct prime numbers such that . A and B are always integers, and might be different for different explosive numbers.nnFor example, the processor will explode when factorizing the number 4505, because 4505 = 1*5*17*53 and 5 = 3*1+2, 17 = 3*5+2 and 53 = 3*17+2 and the numbers 5, 17 and 53 are all prime numbers. In this case A = 3 and B = 2.nnYou are kindly asked to write a computer program that will aid this company in estimating the impact of the errors, by calculating the amount of explosive numbers that exists within a given range of integers.n nnInputnThe input starts with a row containing the number 0 <= N <= 100 of test cases that will follow. For each test case, there will be one row containing two integers, separated by a single space. These numbers are such that .n nnOutputnFor each test case, output the number of explosive numbers that exist innthe range .n nnSample Inputn2n4505 4505n0 5000n nnSample Outputn1n5
机器学习总结(九):梯度消失(vanishing gradient)与梯度爆炸(exploding gradient)问题
(1)梯度不稳定问题:rnrn什么是梯度不稳定问题:深度神经网络中的梯度不稳定性,前面层中的梯度或会消失,或会爆炸。rn原因:前面层上的梯度是来自于后面层上梯度的乘乘积。当存在过多的层次时,就出现了内在本质上的不稳定场景,如梯度消失和梯度爆炸。rnrn(2)梯度消失(vanishing gradient problem):rnrn原因:例如三个隐层、单神经元网络:rnrnrnrn则可以得到:rnr
ZOJ解题报告ZOJ解题报告
ZOJ解题报告ZOJ解题报告ZOJ解题报告ZOJ解题报告
ZOJ刷题题目分类
初学者题:n1001 1037 1048 1049 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889...
HDU - 5934 - Bomb (强连通缩点)
BombTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2468    Accepted Submission(s): 777Problem DescriptionThere are N bombs needing exploding.Ea...
刚才在zoj注册了一个账号
http://acm.zju.edu.cn/n n加油!n n一周做一道题吧nPS: 转载n下面说一下ACM-ICPC队员初用Java编程所遇到的一些问题:n 1、基本输入输出:n (1) JDK 1.5.0 新增的Scanner类为输入提供了良好的基础,简直就是为ACM-ICPC而设的。n 一般用法为:n import java.io.* nnimport java.util.* nnpubli...
浙江大学ZOJ 1004题 详解
第一件事还是翻译题目,这道题目的意思大概是,有多组输入,每组输入有两行,第一行是一个单词(字符串)第二行是另外一个字符串(有可能组成字母都是相同的只不过是字母顺序不同,也有可能是另外的字符串,和原来的字符串没有多大关系),然后給你一个栈,你对这个栈和第一个字符串一共有两种操作,n第一种,压栈操作,执行这种操作会让第一个字符串的第一位放入栈中(就是说如果原来的字符串是madam,执行完一次压栈操作之后
ZOJ Problem Set - 3946 (限制的最短路)
Highway ProjectrnrnTime Limit: 2 Seconds      Memory Limit: 65536 KBrnrnrnEdward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from th
ZOJ-3778-Talented Chef【11th浙江省赛】【贪心】
ZOJ-3778-Talented Chef
zoj题目简单归类zoj题目简单归类
zoj题目简单归类zoj题目简单归类zoj题目简单归类
ZOJ - 3609 (逆元、扩展欧几里得板子)
#include&amp;lt;cstdio&amp;gt;nusing namespace std;ntypedef long long ll;nnll extend_gcd(ll a, ll b, ll &amp;amp;x, ll &amp;amp;y){n if(!a&amp;amp;&amp;amp;!b) return -1;n if(b==0){n x=1; y=0; return a;n }n ll d=extend_gcd(...
zoj1005(广度优先搜索)
题目链接:zoj1005;nn这道题是我第一次用广度优先搜索。虽然之前就知道BFS是怎么回事,但是没在具体题目上用过,所以相比DFS,感觉相对生疏。nn(虽然这道题网上看到可以用数学方法,很轻松解出;但是为了挑战一下BFS,我还是决定死磕一下)nn这道题我看完第一个念头就是搜索。因为每一步就是那几个有限的选择。(虽然题目没说,但是我还是求了最少步骤解出答案的方案,毕竟这种题答案是不唯一的)——考虑...
ZOJ - 4069(2018 青岛现场赛 L) - 指数型生成函数
题目链接:https://vjudge.net/problem/ZOJ-4069nn nn解题思路:nn1.n个点组成环的不同种类数是(n-1)!/2;n个点组成一条链的不同种类数是n!/2,特别的n==1时种类数为1。nn用指数型生成函数表示k个点形成链的种类: 1/2(2x+2!*x^2/2!+3!*x^3/3!+4!*x^4/4!+..+n!*x^n/n!) = 1/2(2*x+x^2+x^...
Cake ZOJ - 3537(判断凸包模板+最优三角剖分+区间dp详解)
Cake ZOJ - 3537nn You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into several triangle-shaped parts for the invited comers. You have a knife to cut. Th...
ZOJ题目答案源码
ZOJ题目答案源码
ZOJ-3953-Intervals【贪心】【17th浙大校赛】
题目大意:nn A:三个区间两两重合nn给你n个区间,让你从中删除几个区间,使得A不成立nn题目思路:贪心。首先将区间以 <font color = 'red'>左值从小到大排序 <font color = 'black'>nn然后遍历三个区间,记x为p[0],y为p[1],从p[2]开始遍历n n 1. 首先判断这三个区间是否两两相交n 2. 如果两两相交:则删去y值最大的那个区间(对后面影响尽量小)
ZOJ 3537-Cake(凸包+最优三角刨分+区间DP)
CakernrnTime Limit: 1 Second      rnMemory Limit: 32768 KB rnrnYou want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into several triangle-shaped parts for th
ZOJ —— 1649 Rescue(搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649nn题目:nnRescuennTime Limit: 2 Seconds      Memory Limit: 65536 KBnnAngel was caught by the MOLIGPY! He was put in prison by Molig...
ZOJ-3261(并查集续路径压缩,灵活应用)
Connections in Galaxy WarrnrnTime Limit: 3 Seconds      rnMemory Limit: 32768 KB rnrnIn order to strengthen the defense ability, many stars in galaxy allied together and built many bidirectional tunne
ZOJ 1586 QS Network(最小生成树)
Sunny Cup 2003 - Preliminary RoundApril 20th, 12:00 - 17:00Problem E: QS NetworkIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each other via ne
Python ZOJ 刷题记录
文章目录AC源码导语及准备工作nAC源码nnnnnnnnnnn1001n1002nnn导语及准备工作nC++先入为主的思维固化,Python看了几遍知识点也记不住,究其原因还是没咋用过n遍访所知的各平台仅ZOJ支持py2.7,cf和leetcode支持3.6/2.7,单独的有pythonTipn一开始在linux下用py2.7 运行:python zoj.py &amp;amp;amp;amp;lt; data.txt不能像在...
ZOJ-3710-Friends【10th浙江省赛】【暴力】
ZOJ-3710-Friends
ZOJ-3939-The Lucky Week【13th浙江省赛】【找规律】
ZOJ-3939-The Lucky Week
FZOJ刷题顺序
FZOJ刷题顺序nn一、练习题(按照学习进度排序)nn二、练习题(按照AC量排序)nn三、往年NOIP原题(按照AC量排序)nn四、往年NOIP原题(按照年份排序)nn注:数据截止2016年1月24日。
ZOJ-3673-1729【数论】【分解质因数】【DFS】【好题】
3673-1729
Lucky Man ZOJ - 4005 (JAVA大整数+牛顿迭代法开根)
Lucky Mannn ZOJ - 4005 nnBaoBao is keen on collection. Recently he is abandoning himself to Kantai Collection, especially to collecting cute girls, known as &quot;Fleet Girls&quot;.nnnnThere are  various types ...
ZOJ-3203-Light Bulb【6th浙江省赛】【数学公式】【三分】
ZOJ-3203-Light Bulb
ZOJ 2305 C Looooops (扩展欧几里得模板题)
C Looooops Time Limit: 2 Seconds      Memory Limit: 65536 KB A Compiler Myster...
zoj 3537 Cake 【凸包 + 区间dp】 【最优三角剖分】
CakernrnTime Limit: 1 Second      Memory Limit: 32768 KBrnrnrnYou want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into several triangle-shaped parts for the
ZOJ3164【背包问题(好题)】
%%%%%%%%%%%%%%%岐爷n这一发从来没写过这么旺盛的背包问题。。。n想法很多,但是好难执行。n题意:n有N种饼干,1-Nn每种最多想买Ki个,ki等于0的话没有上界n对于第i种饼干的权值是Ein第i种饼干的价格Pin有D钱。n还有G组n每组只能选一种。nn思路:n有两种背包,一种是在一定的组里,还有没有特定关系;n没有特定关系的,如果没有限定数或者限定数*花费
ZOJ --- 2974 倒水 【思维 + 矩阵快速幂】
传送门题意 : 就是给你N个瓶子, 每一分钟依次对每一个瓶子进行操作, 分别是将该个瓶子里的水, 倒入所给的瓶子里去, 一共持续m分钟, 最后输出每一个瓶子里的水. n思路 : 不好一眼看出来是矩阵的思想, 这是就需要把样例进行推导, 的然后就可以写出来两个矩阵相乘, 最后得到的就是一个其他矩阵, 所以这道题就是矩阵快速幂. 特别注意下当k等于0时对瓶子的操作. AC 代码:#include<b
zoj 3726 水题+二分
Alice's Print ServicernrnTime Limit: 2 Seconds      Memory Limit: 65536 KBrnrnrnAlice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service fou
ZOJ 2343(贪心)
RobbersrnrnTime Limit: 5 Seconds      Memory Limit: 32768 KB      Special JudgernrnrnN robbers have robbed the bank. As the result of their crime they chanced to get M golden coins. Before the robbery
ZOJ 3780(拓扑排序)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780nn nn题目大意:可以涂黑行,白列,每一行每一列只能涂一次,给最终的图案,要求用最少次数涂出要求的图案并输出步骤。nn nn题目思路:想复杂了,其实由于涂之间是有顺序关系的,所以只要想到拓扑排序这题就非常非常简单了。因为原先是什么颜色都没有的,所以如果想减少...
ZOJ 3954 思维题
题意:已知七段灯abc...可以拼成1..9的所有的数字,(0代表灯亮,就是那种计算器的显示法) 然后给你任意n个数字和他们的01排列每一列都是不同的灯管 问这些排列是否合法rnrn思路:对于任意n个数,他们的abcdef的编码(按列由上到下)是确定的,把这些编码变成一个数 然后塞入map 再把标准的编码塞入map2 看最后map map2是否相等rn代码:rnrn#include n#inclu
Virtual Singers-zoj4043-据说是青岛热身赛题目?
把a,b混在一起排序,常规操作~~a标记-1,b标记1.nn嗯,首先我们可以考虑两个方向,一个是仿照最大流求,最值,一个是dp,因为像这种求数值的题目,方向就是这样,还有其他方向,欢迎留言。nn然后注意两个性质:nn1:如果一个区间内a,b数目都相同,那么这个区间内的a是不会和这个区间之外的b进行匹配的。nn2:言下之意就是我们要确定从那个位置开始确定区间,因为同一个位置的a可能在多个能够满足上述...
【个人训练】(ZOJ3983)Crusaders Quest
题意分析nn和祖玛类似的那种玩法。不过是限定了九个字符,问最好情况下有几次三连碰。 n暴力穷举即可。具体的做法是,先把所有“成块”的字符记录下来,然后一个一个删,再继续这样子递归做下去。考虑到就只有9个字符,内存和时间的占用不会太高。 n这里倒是遇到了盲点:之前不清楚erase的用法。nn代码nnnn#include &amp;lt;bits/stdc++.h&amp;gt;nntypedef long long...
zoj3769(分组背包)
链接:点击打开链接n题意:有13种装备,每种装备只能选一个,每种装备有一个伤害值和防御值,其中如果选Two-Handed的话就不能选Shield和Weapon,Finger可以选两个。求怎样选择,使得在防御值达最小到m的情况下,伤害总值最大。n代码:n#include n#include n#include n#include n#include n#include n#incl
ZOJ - 3593 One Person Game (扩展欧几里得 技巧)@
There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations you can perform
数据结构——优先队列与堆
什么是优先队列?nn普通队列:先进先出,后进后出n优先队列:出队顺序和入队顺序无关;和优先级相关,如医院中,病重先安排病床nn nn优先队列的现实例子:nn①cpu任务调度,动态选择优先级最高的任务执行n②王者荣耀中,攻击键优先打敌人,无敌人时候优先打最近的小兵nn nn关于优先队列的实现:nn普通的线性结构和堆都可以作为优先队列的底层实现。nnnn堆实现优先队列,在最坏的情况下,入队与出队的操作...
文章热词 机器学习教程 Objective-C培训 交互设计视频教程 颜色模型 设计制作学习
相关热词 mysql关联查询两次本表 native底部 react extjs glyph 图标 麦子学院python数据结构 哈工大数据结构视频