Description
There are a lot of bulls in SCAU. One of them loves eating fodder. But his owner – Farmer Cat would not allow him to eat too much fodder, so she plays a game with this bull.
This game is about A SIMPLE MATH PROBLEM : A number between 1 to 230 will be given by the Farmer Cat, and the bull has to tell whether the number can be described by the sum of not less than
two consecutive positive integers or not. If the bull’s answer is right then he can eat the “fodder”, and if not, only “pasture”.
For example, 7 can be described by the sum of 3 and 4. 10 can be described by the sum of 1,2,3 and 4.
For your information, This bull is a genius and he is always able to answer this problem without hesitation. So Farmer Cat asks you for help and write a program to figure out whether
the answer is right or not.
输入格式
The input consists of T test cases.
The number of test cases (T<=200) is given in the first line of the input file.
The next T lines , each line consists a number N (1<=N<230) given by the Farmer Cat and an answer(Can or Can’t) given by the bull.
输出格式
The output should contain T lines, each line consists a word:
If the bull’s answer is right,please print out ”Fodder”.
If it’s wrong.please print out “Pasture”.
输入样例
4
7 Can
7 Can’t
10 Can
10 Can’t
输出样例
Fodder
Pasture
Fodder
Pasture
题意:判断一个数能否分解成连续正整数的和 |
思路:
奇数除了1全满足,偶数除了是2的幂次的全满足。
证明(字迹潦草凑合着看看):
AC代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 3e4+2;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
scanf("%d",&kase);
while(kase--)
{
ll n;
n = read();
char s[15]; scanf("%s",s);
int len = strlen(s);
bool cur = false;
if(len==3) cur = true;
bool flag = false;
if(n&1&&n!=1) flag = true;
else
{
while(n%2==0)
n /= 2;
if(n==1) flag = false;
else flag = true;
}
if(flag==cur) cout<<"Fodder"<<'\n';
else cout<<"Pasture"<<'\n';
}
return 0;
}