文章目录
-
- 1032、The 3n + 1 problem
- 1037、Keep on Truckin'
- 1040、As Easy As A+B
- 1048、The Hardest Problem Ever
- 1056、HangOver
- 1058、Humble Numbers[AC的不容易]
- 1061、Rightmost Digit
- 1070、Milk
- 1076、An Easy Task[闰年]
- 1097、A hard puzzle
- 1098、Ignatius's puzzle
1032、The 3n + 1 problem
Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.
Consider the following algorithm:
1. input n2. print n3. if n = 1 then STOP4. if n is odd then n <- 3n + 15. else n <- n / 26. GOTO 2
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)
Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
Input
The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.
You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.
You can assume that no opperation overflows a 32-bit integer.
Output
For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
Code:
1、重要的是要读懂题目的含义
2、本题求i和j之间所有的数循环的长度的最大值
#include<iostream>
using namespace std;
int algo(int n){
int count=1;while(n!=1){
if(n%2==1){
n=3*n+1;count++;}else{
n=n/2;count++;}}return count;
}
int main(){
int a,b,temp,count;while(cin>>a>>b){
cout<<a<<" "<<b<<" ";if(a>b){
temp=a;a=b;b=temp;}int max=0;for(int i=a;i<=b;i++){
if(algo(i)>max)max=algo(i);}cout<<max<<endl;}return 0;
}
1037、Keep on Truckin’
Boudreaux and Thibodeaux are on the road again . . .
“Boudreaux, we have to get this shipment of mudbugs to Baton Rouge by tonight!”
“Don’t worry, Thibodeaux, I already checked ahead. There are three underpasses and our 18-wheeler will fit through all of them, so just keep that motor running!”
“We’re not going to make it, I say!”
So, which is it: will there be a very messy accident on Interstate 10, or is Thibodeaux just letting the sound of his own wheels drive him crazy?
Input
Input to this problem will consist of a single data set. The data set will be formatted according to the following description.
The data set will consist of a single line containing 3 numbers, separated by single spaces. Each number represents the height of a single underpass in inches. Each number will be between 0 and 300 inclusive.
Output
There will be exactly one line of output. This line will be:
NO CRASH
if the height of the 18-wheeler is less than the height of each of the underpasses, or:
CRASH X
otherwise, where X is the height of the first underpass in the data set that the 18-wheeler is unable to go under (which means its height is less than or equal to the height of the 18-wheeler).
The height of the 18-wheeler is 168 inches.
Sample Input
180 160 170
Sample Output
CRASH 160
Code:
1、读懂题目要求,很简单
#include<iostream>
using namespace std;
int main(){
int a[3];for(int i=0;i<3;i++){
cin>>a[i];}for(int i=0;i<3;i++){
if(a[i]<168){
cout<<"CRASH "<<a[i]<<endl;return 0;}}cout<<"NO CRASH"<<endl;return 0;
}
1040、As Easy As A+B
These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.
Give you some integers, your task is to sort these number ascending (升序).
You should know how easy the problem is now!
Good luck!
Input
Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line.
It is guarantied that all integers are in the range of 32-int.
Output
For each case, print the sorting result, and one line one case.
Sample Input
2
3 2 1 3
9 1 4 7 2 5 8 3 6 9
Sample Output
1 2 3
1 2 3 4 5 6 7 8 9
Code:
1、对动态数组进行排序,sort()
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int n,t,m;vector<int> a;cin>>n;while(n!=0){
n--;cin>>t;for(int i=0;i<t;i++){
cin>>m;a.push_back(m);}sort(a.begin(),a.end());for(int i=0;i<t;i++){
if(i==0){
cout<<a[i];}else{
cout<<" "<<a[i];}}cout<<endl;a.clear();}return 0;
}
1048、The Hardest Problem Ever
Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked.
You are a sub captain of Caesar’s army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is ‘A’, the cipher text would be ‘F’). Since you are creating plain text out of Caesar’s messages, you will do the opposite:
Cipher text
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Plain text
V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.
A single data set has 3 components:
Start line - A single line, “START”
Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar
End line - A single line, “END”
Following the final data set will be a single line, “ENDOFINPUT”.
Output
For each data set, there will be exactly one line of output. This is the original message by Caesar.
Sample Input
START
NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX
END
START
N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
END
START
IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
END
ENDOFINPUT
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
Code
1、将加密后的字符串按一定的规则进行解密
2、将字符串转化为字符数组 strcpy(c,str.c_str());
3、注意输入时候的问题
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main(){
string str,str1,str2;char c[200];while(1){
getline(cin,str1);getline(cin,str);getline(cin,str2);if(str1=="ENDOFINPUT") break;strcpy(c,str.c_str());//将字符串str转化为字符数组c; for(int i=0;c[i]!='\0';i++){
if(c[i]==' '||c[i]==','){
continue;}else if(c[i]>'E'){
c[i]=c[i]-5;}else{
c[i]=c[i]+21;}}str=c;cout<<str<<endl;}return 0;
}
1056、HangOver
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We’re assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + … + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Sample Input
1.00
3.71
0.04
5.19
0.00
Sample Output
3 card(s)
61 card(s)
1 card(s)
273 card(s)
Code:
1、计算(1/2+1/3+1/4+…1/n)大于某一指定数时n的最小值
#include<iostream>
using namespace std;
int main(){
//c[0.01 5.20]float c,sum;int count;while(cin>>c){
if(c==0.00) return 0;sum=0,count=0;for(float i=2;sum<c;i++){
count++;sum=sum+(1/i);}cout<<count<<" card(s)"<<endl;}return 0;
}
1058、Humble Numbers[AC的不容易]
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, … shows the first 20 humble numbers.
Write a program to find and print the nth element in this sequence
Input
The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.
Output
For each test case, print one line saying “The nth humble number is number.”. Depending on the value of n, the correct suffix “st”, “nd”, “rd”, or “th” for the ordinal number nth has to be used like it is shown in the sample output.
Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
Sample Output
The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 5842nd humble number is 2000000000.
方法一:超时
#include<iostream>
using namespace std;
//如何判断一个数是否为humble number,即一个数有且仅有质因数2、3、5、7
bool humble(int n){
while(n%2==0){
n=n/2; }while(n%3==0){
n=n/3;}while(n%5==0){
n=n/5;}while(n%7==0){
n=n/7;}if(n==1)return 1;elsereturn 0;
}
int main(){
int n,count,i;//n[1,5842]while(cin>>n){
if(n==0) return 0;count=0;for(i=1;count<n;i++){
if(humble(i)==1)count++;//计数,第几个humble数 }if(n==11||n==12||n==13){
cout<<"The "<<n<<"th humble number is "<<i-1<<"."<<endl;}else if(n%10==1){
cout<<"The "<<n<<"st humble number is "<<i-1<<"."<<endl;}else if(n%10==2){
cout<<"The "<<n<<"nd humble number is "<<i-1<<"."<<endl;}else if(n%10==3){
cout<<"The "<<n<<"rd humble number is "<<i-1<<"."<<endl;}else{
cout<<"The "<<n<<"th humble number is "<<i-1<<"."<<endl;} } return 0;
}
方法二 居然也超时了
#include <iostream>
#include <string>
#define MaxLen 6000
using namespace std; //用于求出4个数的最小值
int compare(int chenTwo,int chenThree,int chenFive,int chenSeven){
int minNum=chenTwo;if(minNum>chenThree){
minNum=chenThree;}if(minNum>chenFive){
minNum=chenFive;}if(minNum>chenSeven){
minNum=chenSeven;}return minNum;
}
//找出第n个丑数int humble(int n){
int ugly[MaxLen]={
1}; //用于保存丑数的数组,将丑数1存入数组中int count=1; //数组中仅有丑数1,所以计数器为1if(n==1) return 1;while(1){
int chenTwo = 0;int chenThree = 0;int chenFive = 0;int chenSeven=0;/*ugly数组中最新的一个丑数为ugly[count-1],ugly[count-1]之前的丑数与2相乘,求出第一个乘积大于ugly[count-1]的值保存在chenTwo中*/for(int i = 0 ; i < count ; i++){
if(ugly[i]*2 >ugly[count-1]){
chenTwo = ugly[i]*2;break;}}/*ugly数组中最新的一个丑数为ugly[count-1],ugly[count-1]之前的丑数与3相乘,求出第一个乘积大于ugly[count-1]的值保存在chenThree中*/for(int i = 0 ; i < count ; i++){
if(ugly[i]*3 >ugly[count-1]){
chenThree = ugly[i]*3;break;}}/*ugly数组中最新的一个丑数为ugly[count-1],ugly[count-1]之前的丑数与5相乘,求出第一个乘积大于ugly[count-1]的值保存在chenFive中*/for(int i = 0 ; i < count ; i++){
if(ugly[i]*5 >ugly[count-1]){
chenFive = ugly[i]*5;break;}}for(int i=0;i<count;i++){
if(ugly[i]*7>ugly[count-1]){
chenSeven=ugly[i]*7;break;}}//chenTwo,chenThree,chenFive,chenSeven的最小值为新的丑数,存入ugly数组中ugly[count]=compare(chenTwo, chenThree, chenFive,chenSeven);count++;if(count==n) //第N个丑数return ugly[count-1];}
}int main(){
int n,a;while(cin>>n){
if(n==0) return 0;a=humble(n);if(n==11||n==12||n==13){
cout<<"The "<<n<<"th humble number is "<<a<<"."<<endl;}else if(n%10==1){
cout<<"The "<<n<<"st humble number is "<<a<<"."<<endl;}else if(n%10==2){
cout<<"The "<<n<<"nd humble number is "<<a<<"."<<endl;}else if(n%10==3){
cout<<"The "<<n<<"rd humble number is "<<a<<"."<<endl;}else{
cout<<"The "<<n<<"th humble number is "<<a<<"."<<endl;} }return 0;
}
方法三:不超时了,终于AC
#include <iostream>
#include <string>
#define MaxLen 6000
using namespace std;
int ugly[MaxLen];
//用于求出4个数的最小值
int compare(int chenTwo,int chenThree,int chenFive,int chenSeven){
int minNum=chenTwo;if(minNum>chenThree){
minNum=chenThree;}if(minNum>chenFive){
minNum=chenFive;}if(minNum>chenSeven){
minNum=chenSeven;}return minNum;
}//利用数组存储前5842个丑数
int humble(){
ugly[0]=0;ugly[1]=1; //用于保存丑数的数组,将丑数1存入数组中for(int j=2;j<=5842;j++){
int chenTwo = 0;int chenThree = 0;int chenFive = 0;int chenSeven=0;/*ugly数组中最新的一个丑数为ugly[j-1],ugly[j-1]之前的丑数与2相乘,求出第一个乘积大于ugly[j-1]的值保存在chenTwo中*/for(int i = 1 ; i < j ; i++){
if(ugly[i]*2 >ugly[j-1]){
chenTwo = ugly[i]*2;break;}}/*ugly数组中最新的一个丑数为ugly[j-1],ugly[j-1]之前的丑数与3相乘,求出第一个乘积大于ugly[j-1]的值保存在chenThree中*/for(int i = 1 ; i < j ; i++){
if(ugly[i]*3 >ugly[j-1]){
chenThree = ugly[i]*3;break;}}/*ugly数组中最新的一个丑数为ugly[j-1],ugly[j-1]之前的丑数与5相乘,求出第一个乘积大于ugly[j-1]的值保存在chenFive中*/for(int i = 1 ; i < j ; i++){
if(ugly[i]*5 >ugly[j-1]){
chenFive = ugly[i]*5;break;}}for(int i=1;i<j;i++){
if(ugly[i]*7>ugly[j-1]){
chenSeven=ugly[i]*7;break;}}//chenTwo,chenThree,chenFive,chenSeven的最小值为新的丑数,存入ugly数组中ugly[j]=compare(chenTwo, chenThree, chenFive,chenSeven);} return 0;
}int main(){
int n,a;humble();while(cin>>n){
if(n==0) return 0;if(n%10==1&&n%100!=11){
cout<<"The "<<n<<"st humble number is "<<ugly[n]<<"."<<endl;}else if(n%10==2&&n%100!=12){
cout<<"The "<<n<<"nd humble number is "<<ugly[n]<<"."<<endl;}else if(n%10==3&&n%100!=13){
cout<<"The "<<n<<"rd humble number is "<<ugly[n]<<"."<<endl;}else{
cout<<"The "<<n<<"th humble number is "<<ugly[n]<<"."<<endl;} }return 0;
}
1061、Rightmost Digit
Given a positive integer N, you should output the most right digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
Sample Input
2
3
4
Sample Output
7
6
Code:
1、计算nn,找规律进行运算
#include<iostream>
using namespace std;
int main(){
int t,n;//n[1,1000,000,000]while(cin>>t){
for(int i=0;i<t;i++){
cin>>n;//尾数为0、1、5、6、9的数,运算后尾数不变 if(n%10==0||n%10==1||n%10==5||n%10==6||n%10==9) cout<<n%10<<endl;//尾数为4的数,运算后尾数为6 else if(n%10==4){
cout<<6<<endl;}//尾数为2的数 else if(n%10==2){
if(n%4==2)cout<<4<<endl;else cout<<6<<endl;}//尾数为3的数 else if(n%10==3){
if(n%4==3)cout<<7<<endl;elsecout<<3<<endl;}//尾数为7的数 else if(n%10==7){
if(n%4==3)cout<<3<<endl;elsecout<<7<<endl;}//尾数为8的数 else{
if(n%4==0)cout<<6<<endl;elsecout<<4<<endl;}}}return 0;
1070、Milk
Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. There are many kinds of milk in the supermarket, so Ignatius wants to know which kind of milk is the cheapest.
Here are some rules:
- Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6(inclusive).
- Ignatius drinks 200mL milk everyday.
- If the milk left in the bottle is less than 200mL, Ignatius will throw it away.
- All the milk in the supermarket is just produced today.
Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200mL, you should ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case starts with a single integer N(1<=N<=100) which is the number of kinds of milk. Then N lines follow, each line contains a string S(the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P(Yuan) which is the price of a bottle, V(mL) which is the volume of a bottle.
Output
For each test case, you should output the brand of the milk which is the cheapest. If there are more than one cheapest brand, you should output the one which has the largest volume.
Sample Input
2
2
Yili 10 500
Mengniu 20 1000
4
Yili 10 500
Mengniu 20 1000
Guangming 1 199
Yanpai 40 10000
Sample Output
Mengniu
Mengniu
Code:
1、找出最便宜的牛奶
2、将每一种品牌的牛奶信息存入一个string类型的二维数组,将二维数组中表示价格和容量的string字符串转变为整型变量,计算出每种牛奶每天需要的价格,存入数组num[]中,在数组num[]中找出最小的值
3、将字符串转变为整数的函数String s1,int a=atoi(s.c_str)
#include<iostream>
#include<vector>
#include<string>
#include <stdlib.h>
#define MAX_LEN 100000;
using namespace std;
int main(){
int t,n,s,cheap,num[100];//n[1,100]//t个测试用例 while(cin>>t){
for(int i=0;i<t;i++){
cin>>n;//牛奶的种类 //定义一个n行3列的动态二维数组 vector<vector <string> >s(n); for(int i=0;i<n;i++){
s[i].resize(3);}//输入牛奶类型 for(int i=0;i<n;i++){
for(int j=0;j<3;j++){
cin>>s[i][j];}} //在s[i][j]数组中找出最便宜的牛奶int temp;for(int i=0;i<n;i++){
if(atoi(s[i][2].c_str())>200){
temp=(atoi(s[i][2].c_str())/200);if(temp>5){
temp=5;}num[i]=atoi(s[i][1].c_str())/temp;}else{
num[i]=MAX_LEN;}} //num[]每天多少元int min=MAX_LEN;for(int i=0;i<n;i++){
if(num[i]<min){
min=num[i];cheap=i;}else if(num[i]==min){
if(atoi(s[i][2].c_str())>atoi(s[cheap][2].c_str())){
cheap=i;} }}cout<<s[cheap][0]<<endl;}}
}
1076、An Easy Task[闰年]
Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him?
Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from year Y.
Note: if year Y is a leap year, then the 1st leap year is year Y.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains two positive integers Y and N(1<=N<=10000).
Output
For each test case, you should output the Nth leap year from year Y.
Sample Input
3
2005 25
1855 12
2004 10000
Sample Output
2108
1904
43236
Code:
1、闰年:能被4整除但不能被100整除,或者能被400整除
2、查找从起始年份y开始,第n个闰年
//闰年
#include<iostream>
using namespace std;
bool leap(int n){
if((n%4==0&&n%100!=0)||n%400==0){
return 1;}else{
return 0;}
}
int main(){
int t;while(cin>>t){
int y,n,count,year;//y代表起始年份,n[1,10000] for(int i=0;i<t;i++){
cin>>y>>n;count=0;for(int j=y;count<n;j++){
if(leap(j)==1){
count++;year=j;}}cout<<year<<endl;}}
}
1097、A hard puzzle
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b’s the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
Output
For each test case, you should output the a^b’s last digit number.
Sample Input
7 66
8 800
Sample Output
9
6
Code:
1、计算ab的个位数字为多少,要找到规律(通过尾数)
#include<iostream>
using namespace std;
int main(){
int a,b;//a,b(0,2^30]while(cin>>a>>b){
if(a%10==0||a%10==1||a%10==6||a%10==5) cout<<a%10<<endl;//尾数为2 else if(a%10==2){
if(b%4==1)cout<<2<<endl;else if(b%4==2)cout<<4<<endl;else if(b%4==3)cout<<8<<endl;elsecout<<6<<endl;}//尾数为3else if(a%10==3){
if(b%4==1)cout<<3<<endl;else if(b%4==2)cout<<9<<endl;else if(b%4==3)cout<<7<<endl;elsecout<<1<<endl;}//尾数为4else if(a%10==4){
if(b%2==1)cout<<4<<endl;elsecout<<6<<endl;}//尾数为7else if(a%10==7){
if(b%4==1)cout<<7<<endl;else if(b%4==2)cout<<9<<endl;else if(b%4==3)cout<<3<<endl;elsecout<<1<<endl;}//尾数为8else if(a%10==8){
if(b%4==1)cout<<8<<endl;else if(b%4==2)cout<<4<<endl;else if(b%4==3)cout<<2<<endl;elsecout<<6<<endl;} //尾数为9else if(a%10==3){
if(b%2==1)cout<<9<<endl;elsecout<<1<<endl;} }return 0;
1098、Ignatius’s puzzle
Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5x13+13x5+kax,input a nonegative integer k(k<10000),to find the minimal nonegative integer a,make the arbitrary integer x ,65|f(x)if
no exists that a,then print “no”.
Input
The input contains several test cases. Each test case consists of a nonegative integer k, More details in the Sample Input.
Output
The output contains a string “no”,if you can’t find a,or you should output a line contains the a.More details in the Sample Output.
Sample Input
11
100
9999
Sample Output
22
no
43
Code:
1、给定一个k值,使得对于任意x,f(x)=5x13+13x5+kax可以被65整除,找出使其成立的a的最小值
//判断(18+k*a)%65==0
//给定一个k值,使得对于任意x,f(x)=5*x^13+13*x^5+k*a*x可以被65整除,找出使其成立的a的最小值
//f(1)=18+k*a可以被65整除
#include<iostream>
using namespace std;
int main(){
int k,a;while(cin>>k){
for(a=1;a<=65;a++){
if((18+k*a)%65==0){
cout<<a<<endl;break;}}if(a>65)cout<<"no"<<endl;}return 0;
}