大菜鸡的数论之旅-[kuangbin]数学训练一
A题 LightOJ 1008 Fibsieve`s Fantabulous Birthday
Problem Description
Fibsieve had a fantabulous (yes, it’s an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.
Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.
The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.
In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.
Output
For each case you have to print the case number and two numbers (x, y), the column and the row number.
Sample Input
3
8
20
25
Sample Output
Case 1: 2 3
Case 2: 5 4
Case 3: 1 5
-----------------------------------------分割线----------------------------------------------------------------------------------
代码
#include <bits/stdc++.h>
#define __bug(x) cout<<"test:"<<x<<endl;
using namespace std;
typedef long long ll;
const int N=1e5+5;
int main()
{
int T;
cin>>T;
for(int cas=1; cas<=T; cas++)
{
ll xx;
cin>>xx;
if(xx==1)
{
cout<<"Case "<<cas<<": "<<1<<" "<<1<<"\n";
continue;
}
ll l=1,r=1e8;
ll mid;
ll ans=1;
while(l<=r)
{
mid=(l+r)/2;
if(mid*mid<xx)
{
l=mid+1;
ans=mid;
}
else
{
r=mid-1;
}
}
// __bug(ans);
ll x,y;
ll last=xx-ans*ans;
// __bug(last);
if(ans%2==0)
{
if(last<=((ans+1)*2-1)/2)
{
x=ans+1;
y=last;
}
else
{
y=ans+1;
x=(ans+1-(last-((ans+1)*2-1)/2))+1;
}
}
else
{
if(last<=((ans+1)*2-1)/2)
{
y=ans+1;
x=last;
}
else
{
x=ans+1;
y=(ans+1-(last-((ans+1)*2-1)/2))+1;
}
}
cout<<"Case "<<cas<<": "<<x<<" "<<y<<"\n";
}
return 0;
}
--------------------------------------------------------------分割线-------------------------------------------------------------
B题 LightOJ 1010 Knights in Chessboard
Problem Description
Given an m x n chessboard where you want to place chess knights. You have to find the number of maximum knights that can be placed in the chessboard such that no two knights attack each other.
Those who are not familiar with chess knights, note that a chess knight can attack 8 positions in the board as shown in the picture below.
Input
Input starts with an integer T (≤ 41000), denoting the number of test cases.
Each case contains two integers m, n (1 ≤ m, n ≤ 200). Here m and n corresponds to the number of rows and the number of columns of the board respectively.
Output
For each case, print the case number and maximum number of knights that can be placed in the board considering the above restrictions.
Sample Input
3
8 8
3 7
4 10
Sample Output
Case 1: 32
Case 2: 11
Case 3: 20
----------------------------------------------------------分割线-----------------------------------------------------------------
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++)
{
ll n,m;
cin>>n>>m;
if(n==1)
{
printf("Case %d: ",cas);
cout<<m<<endl;
continue;
}
if(m==1)
{
printf("Case %d: ",cas);
cout<<n<<endl;
continue;
}
if(n==2)
{
printf("Case %d: ",cas);
if(m%4<=2)
{
cout<<(m/4)*4+(m%4)*2<<endl;
}
else
{
cout<<(m/4)*4+4<<endl;
}
continue;
}
if(m==2)
{
printf("Case %d: ",cas);
if(n%4<=2)
{
cout<<(n/4)*4+(n%4)*2<<endl;
}
else
{
cout<<(n/4)*4+4<<endl;
}
continue;
}
printf("Case %d: ",cas);
cout<<(n*m+1)/2<<endl;
}
return 0;
}
---------------------------------------------------------分割线------------------------------------------------------------------
C题 LightOJ 1020 A Childhood Game
Problem Description
Alice and Bob are playing a game with marbles; you may have played this game in childhood. The game is playing by alternating turns. In each turn a player can take exactly one or two marbles.
Both Alice and Bob know the number of marbles initially. Now the game can be started by any one. But the winning condition depends on the player who starts it. If Alice starts first, then the player who takes the last marble looses the game. If Bob starts first, then the player who takes the last marble wins the game.
Now you are given the initial number of marbles and the name of the player who starts first. Then you have to find the winner of the game if both of them play optimally.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n < 231) and the name of the player who starts first.
Output
For each case, print the case number and the name of the winning player.
Sample Input
3
1 Alice
2 Alice
3 Bob
Sample Output
Case 1: Bob
Case 2: Alice
Case 3: Alice
-------------------------------------------------------分隔线--------------------------------------------------------------------
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
const ll MOD=1e9+7;
const double PI=acos(-1);
int main()
{
int T;
scanf("%d",&T);
for(int cas=1; cas<=T; cas++)
{
int n;
char name[10];
scanf("%d%s",&n,name);
if(name[0]=='A')
{
if(n%3==1)
{
printf("Case %d: Bob\n",cas);
}
else
{
printf("Case %d: Alice\n",cas);
}
}
else
{
if(n%3==0)
{
printf("Case %d: Alice\n",cas);
}
else
{
printf("Case %d: Bob\n",cas);
}
}
}
return 0;
}
-----------------------------------------------------------分割线----------------------------------------------------------------
D题 LightOJ 1078 Integer Divisibility
Problem Description
If an integer is not divisible by 2 or 5, some multiple of that number in decimal notation is a sequence of only a digit. Now you are given the number and the only allowable digit, you should report the number of digits of such multiple.
For example you have to find a multiple of 3 which contains only 1’s. Then the result is 3 because is 111 (3-digit) divisible by 3. Similarly if you are finding some multiple of 7 which contains only 3’s then, the result is 6, because 333333 is divisible by 7.
Input
Input starts with an integer T (≤ 300), denoting the number of test cases.
Each case will contain two integers n (0 < n ≤ 106 and n will not be divisible by 2 or 5) and the allowable digit (1 ≤ digit ≤ 9).
Output
For each case, print the case number and the number of digits of such multiple. If several solutions are there; report the minimum one.
Sample Input
3
3 1
7 3
9901 1
Sample Output
Case 1: 3
Case 2: 6
Case 3: 12
--------------------------------------------分割线-------------------------------------------------------------------------------
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++)
{
int n,digit;
scanf("%d%d",&n,&digit);
int ans=0;
int num=digit;
while(num%n!=0)
{
num=num*10+digit;
num=num%n;
ans++;
}
ans++;
printf("Case %d: %d\n",cas,ans);
}
return 0;
}
-------------------------------------------分割线--------------------------------------------------------------------------------
E题 LightOJ 1116 Ekka Dokka
Problem Description
Ekka and his friend Dokka decided to buy a cake. They both love cakes and that’s why they want to share the cake after buying it. As the name suggested that Ekka is very fond of odd numbers and Dokka is very fond of even numbers, they want to divide the cake such that Ekka gets a share of N square centimeters and Dokka gets a share of M square centimeters where N is odd and M is even. Both N and M are positive integers.
They want to divide the cake such that N * M = W, where W is the dashing factor set by them. Now you know their dashing factor, you have to find whether they can buy the desired cake or not.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer W (2 ≤ W < 263). And W will not be a power of 2.
Output
For each case, print the case number first. After that print “Impossible” if they can’t buy their desired cake. If they can buy such a cake, you have to print N and M. If there are multiple solutions, then print the result where M is as small as possible.
Sample Input
3
10
5
12
Sample Output
Case 1: 5 2
Case 2: Impossible
Case 3: 3 4
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++)
{
ll n;
scanf("%lld",&n);
ll even=1;
while(n%2==0)
{
even*=2;
n/=2;
}
if(even==1)
{
printf("Case %d: Impossible\n",cas);
}
else
{
printf("Case %d: %lld %lld\n",cas,n,even);
}
}
return 0;
}