Ошибка в печати длинного длинного int

Я новичок в C ++. Я написал программу, которая использует unsigned long long int тип данных.

Я не могу правильно распечатать переменную

вот код:

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t ;
int x = scanf("%d",&t);

unsigned long long int a,b,c;
unsigned long long int counter,n ,mod = pow(10,9)+7;

while (t>0){
int y = scanf("%llu,%llu,%llu",&a,&b,&n);
//printf("%llu\n",a);
if (n == 1){
printf("%llu",b);
}else if (n == 0){
printf("%llu",a);
}else{
c = 0;
counter =2;
while (counter <= n){
c = a+b;
a = b;
b = c;
++counter;
}
if (c>mod)
c=c-mod;
printf("%llu",c);
}
--t;
}
return 0;
}

Стандартный ввод:

8
2 3 1
9 1 7
9 8 3
2 4 9
1 7 2
1 8 1
4 3 1
3 7 5

Ожидаемый результат:

3
85
25
178
8
8
3
44

Наблюдаемый вывод:

23191798

-1

Решение

В отличие от Java println функция, printf делает не добавить разрыв строки.
Если вы хотите, чтобы это сделать, добавьте «\ П» к вашей строке.

printf("some text\n");
1

Другие решения


По вопросам рекламы [email protected]