Description John's N (1≤n≤1,000,000,000) cows are set off to explore the land around the ranch. They will walk along a road until they reach the fork (it can be thought that all intersections are like this). This time, the herd of cows may be divided into two groups, along the next two roads continue to walk. If they go to the fork again, it is still possible to continue to split into two groups to continue walking. The way the cows split is odd: if the cows can be precisely divided into two parts, the two parts of the cattle are exactly the same as K (1≤k≤1000), then the fork herd will split. Otherwise, the herd will not split, and they'll all stay here and eat grass peacefully. Please calculate how many cows will eventually eat grass in a calm manner. Input
two integers n and K.
Output
The last number of herds.
Sample INPUT6 2
INPUT DETAILS:
There is 6 cows and the difference in group sizes is 2.
Sample OUTPUT3
OUTPUT DETAILS:
There is 3 final groups (with 2, 1, and 3 cows in them).
6
/ \
2 4
/ \
1 3 Direct violence recursion on Ah, anyway 0MSPascal dafa good, instantly brush on the # # but the front 88KB is how to do it ...
#include <cstdio>using namespacestd;intn,m;intAintN) { if(n>m&& (n-m)%2==0)returnA ((n-m)/2) +a ((n+m)/2);return 1;}intMain () {scanf ("%d%d",&n,&m); printf ("%d\n", A (n));}
var n,m:longint;function F (n:longint): Longintbegin if 2=022); exit (1); End;beginread (n,m); write (f (n)); end.
bzoj:1621: [Usaco2008 open]roads Around the Farm Fork Junction