John Horton Conway, a British mathematician active in recreational mathematics, proposed a conjecture in 2014: arrange the factors of any given number in ascending order, and pull the exponents down, we can get another number. Keep doing so we must end up at a prime number.
Now you are supposed to write a program to make one step verification of this conjecture. That is, for any given positive integer N, you must factorize it, and then test if the number obtained from its factors is a prime.
For each case, first print in a line the number obtained from N’s factors. The in the next line, print Yes if the above number is a prime, or No if not.
2329
17137
Yes
124
2231
No
87516
2232111317
No
#include
using namespace std;
bool isprime(long long n){
if(n <= 1) return 0;
for(long long i =2 ; i <= sqrt(1.0 * n); i++){
if(n % i == 0) return 0;
}
return 1;
}
string s;
int main(){
long long num,temp, cnt = 0;
cin >> num;
temp = num;
for(long long i = 2; i < num; i++){
long long cnt = 0;
while(temp % i ==0){
cnt++;
temp /= i;
}
if(cnt >= 1){
if(cnt > 1)
s = s + to_string(i) + to_string(cnt);
else
s = s + to_string(i);
}
}
cout << s << endl;
if(isprime(stoll(s)))
cout << "Yes";
else
cout << "No";
return 0;
}
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤105 ) which is the total number of nodes, and an integer 1≤k Then N lines follow, each describes a node in the format: Address Data Next For each case, output in order the resulting linked list. Each node occupies a line, and is printed in the same format as in the input. 00100 6 4 00000 4 68237 Given an initially empty hash table HT of size 11. The hash function is H(key)=key%7, with linear probing used to resolve the collisions. Now hash the keys 87, 40, 30, 6, 11, 22, 98 and 20 one by one into HT. What is the average search time for unsuccessful searches? The answer is 6. Now you are supposed to write a program to solve this kind of problems. Each input file contains one test case. For each case, the first line gives 3 positive integers TSize (≤103 , the table size), M (≤TSize, the divisor in the hash function), and N (≤TSize, the number of integers to be inserted). Then N non-negative integers (≤104) are given in the next line, separated by spaces. Print in a line the average search time for unsuccessful searches, after hashing the N integers into the table. The answer must be accurate up to 1 decimal place. 11 7 8 6.0 3 3 3 4.0
where Address is the position of the node, Data is a positive integer no more than 105 , and Next is the position of the next node. It is guaranteed that there are at least two nodes on the list.Output Specification:
Sample Input:
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218Sample Output:
68237 6 33218
33218 3 99999
99999 5 12309
12309 2 00100
00100 1 -1Note
Code
#include
7-3 Unsuccessful Searches
The above figure is a question from GRE-CS 2018. It states:Input Specification:
Output Specification:
Sample Input 1:
87 40 30 6 11 22 98 20Sample Output 1:
Sample Input 2:
81 2 5Sample Output 2:
Note
Code1
#include
7-4 Ambulance Dispatch