int Solution::sumR(TreeNode* root, int x)
{
	if (root->right == nullptr && root->left == nullptr)
		return 10 * x + root->val;
	int val = 0;
	if (root->left != nullptr)
		val += sumR(root->left, 10 * x + root->val);
	if (root->right != nullptr)
		val += sumR(root->right, 10 * x + root->val);
	return val;
}
		/* Sum contributions from all threads, save to _force&_torque.
		 * Locks globalMutex, since one thread modifies common data (_force&_torque).
		 * Must be called before get* methods are used. Exception is thrown otherwise, since data are not consistent. */
		inline void sync(){
			for(int i=0; i<nThreads; i++){
				if (_maxId[i] > 0) { synced = false;}
			}
			if(synced) return;
			boost::mutex::scoped_lock lock(globalMutex);
			if(synced) return; // if synced meanwhile
			
			for(int i=0; i<nThreads; i++){
				if (_maxId[i] > 0) { ensureSize(_maxId[i],i);}
			}
			
			syncSizesOfContainers();

			for(long id=0; id<(long)size; id++){
				Vector3r sumF(Vector3r::Zero()), sumT(Vector3r::Zero());
				for(int thread=0; thread<nThreads; thread++){ sumF+=_forceData[thread][id]; sumT+=_torqueData[thread][id];}
				_force[id]=sumF; _torque[id]=sumT;
				if (permForceUsed) {_force[id]+=_permForce[id]; _torque[id]+=_permTorque[id];}
			}
			if(moveRotUsed){
				for(long id=0; id<(long)size; id++){
					Vector3r sumM(Vector3r::Zero()), sumR(Vector3r::Zero());
					for(int thread=0; thread<nThreads; thread++){ sumM+=_moveData[thread][id]; sumR+=_rotData[thread][id];}
					_move[id]=sumM; _rot[id]=sumR;
				}
			}
			synced=true; syncCount++;
		}
crv::Internal<int> sumR(const crv::Internal<int> a, const crv::Internal<int> b, const crv::Internal<int> k) {
  crv::Internal<int> sum = a + b*k;
  if (dfs_checker().BRANCH_CALL(k > 0))
    return sum + sumR(a, b, k-1);
  else
    return sum;
}
Beispiel #4
0
// N must be even
int main() {
#ifdef ENABLE_CPROVER
  int a = nondet_int();
  int b = nondet_int();

  __CPROVER_assume(a < 16384);
  __CPROVER_assume(b < 16384);
#elif ENABLE_KLEE
  int a;
  int b;

  klee_make_symbolic(&a, sizeof(a), "a");
  klee_make_symbolic(&b, sizeof(b), "b");

  if (a >= 16384)
    return 0;

  if (b >= 16384)
    return 0;
#endif

  int result = sumR(a, b, N);
#ifndef FORCE_BRANCH
  assert(result == ((a*(N+1)) + (b*(N+1)*(N/2))));
#endif

  return 0;
}
Beispiel #5
0
int sumR(int a, int b, int k) {
  int sum = a + b*k;
  if (k > 0)
    return sum + sumR(a, b, k-1);
  else
    return sum;
}
// N must be even
void crv_main() {
  crv::Internal<int> a, b;
  dfs_checker().add_assertion(a < 16384);
  dfs_checker().add_assertion(b < 16384);

  crv::Internal<int> result = sumR(a, b, N);
  dfs_checker().add_error(result != ((a*(N+1)) + (b*(N+1)*(N/2))));
}
int Solution::sumNumbers(TreeNode *root)
{
	if (root == nullptr)
		return 0;
	return sumR(root, 0);
}