#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
ll sum(ll n)
{
return n*n;
}
int main()
{
ll i, lev, lim, mid;
while (cin >> i && i)
{
lev = (ll)ceil(sqrt(i));
if (lev&1)
{
lim = lev*lev;
mid = lim - (lev-1);
if (i<mid)
{
cout << lev << " " << i-(lev-1)*(lev-1) << endl;
} else
{
cout << lim-(i)+1 << " " << lev << endl;
}
} else
{
lim = lev*lev;
mid = lim - (lev-1);
if (i>=mid)
{
cout << lev << " " << lim-i+1 << endl;
} else
{
cout << i-(lev-1)*(lev-1) << " " << lev << endl;
}
}
}
return 0;
}
Showing posts with label Sequence. Show all posts
Showing posts with label Sequence. Show all posts
Thursday, November 10, 2011
[UVa] 10161 - Ant on a Chess Board
Wednesday, October 26, 2011
[UVa] 11000 - Bee
This is all about careful reading and a very bit of analysis.
First analyze what happens with a Male bee. You'll see every year the number of bees in that tree is a Fibonacci number, since all the past bees are dead by then.
Then for a Female be, it's actually the same, because it gives birth to a Male bee the next year. And since the special bee produces one Male bee each year, so the result is actually the sum of Fibonacci numbers till n.
First analyze what happens with a Male bee. You'll see every year the number of bees in that tree is a Fibonacci number, since all the past bees are dead by then.
Then for a Female be, it's actually the same, because it gives birth to a Male bee the next year. And since the special bee produces one Male bee each year, so the result is actually the sum of Fibonacci numbers till n.
#include <iostream>
#include <cmath>
using namespace std;
long long sum[100], fibs[100];
int fib( ) {
int i;
long long lim = (long long)pow(2.00,32);
fibs[0]=0LL; sum[0]=0LL;
fibs[1]=1LL; sum[1]=1LL;
fibs[2]=1LL; sum[2]=2LL;
for (i=3 ; sum[i-1]<lim ; i++) {
fibs[i]=fibs[i-1]+fibs[i-2];
sum[i]=sum[i-1]+fibs[i];
}
return i;
}
int main( ) {
fib();
int n;
while (cin >> n && n>=0)
{
cout << sum[n] << " " << sum[n+1] << endl;
}
return 0;
}
Subscribe to:
Posts (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...