View difference between Paste ID: uWtJTSYt and Uw8NfT18
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <math.h>
3
4
int main(){
5
	long long i,k;
6
	scanf("%lld",&k);
7
	i=0;
8
	//tim so i lon nhat thoa man tong 2^1+2^2+...+2^i<= k <=> 2^(i+1)-2<=k
9
	while((pow(2,i+1)-2)<k){
10
		i++;
11
	}
12
	//stt nam trong doan [i^2 --> i^2+2^i]
13
	//2^(i-1)+1 <= k <= 2^i
14
	//===> stt= i^2 + (k-2^(i-1)) neu i>1
15-
	//      stt=k-1               neu i=1
15+
	//      stt=k+1               neu i=1
16
	printf("%d\n",i);
17-
	if(i==1) printf("%lld",k-1);
17+
	if(i==1) printf("%lld",k+1);
18
	else printf("%1.0f",i*i+(k-pow(2,i-1)));
19
	getch();
20
	return 0;
21
}