Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
multiply two numbers (previous)
#include<cstdio> #include<string.h> using namespace std; typedef long long int ll; ll a[100001], b[100001], ans[300001], n1, n2; void initialize(){ for(int j=0; j<300001; j++) ans[j] = 0; return; } void multiply(){ for(int j=0; j<n1; j+=17){ ll temp = 0, curr, counts = 0; if(j + 16 < n1) curr = j+16; else{ curr = n1 - 1; counts = 17 - (n1 - 1 - j + 1); } while(counts < 17){ temp = temp*10 + a[curr]; curr--; counts++; } curr = j; ll carry = 0; for(int i = n2 - 1; i >= 0; i--){ ans[curr] += temp*b[i] + carry; carry = ans[curr]/10; ans[curr] = ans[curr] % 10; curr++; } while(carry){ ans[curr++] = carry % 10; carry /= 10; } } return; } void take_input(){ initialize(); //printf("enter the sizes of the two array : "); //scanf("%d %d",&n1 ,&n2); //printf("enter the two numbers : "); char ch[100001]; scanf("%s",&ch); n1 = strlen(ch); for(int j=0; j<n1; j++) /// note that here a is made reversed... a[j] = ch[n1 - j - 1] - '0'; scanf("%s",ch); n2 = strlen(ch); for(int j=0; j<n2; j++) b[j] = ch[j] - '0'; return; } void print_result(){ int j = 200001; while(j >= 0 && ans[j] == 0) j--; if(j < 0){ printf("0\n"); return; } for(; j >= 0; j--) printf("%d",ans[j]); printf("\n"); return; } int main(){ int t; //printf("enter the number of test case : "); scanf("%d",&t); while(t--){ take_input(); multiply(); print_result(); } return 0; }
run
|
edit
|
history
|
help
0
Working variables benchmark
proga2
next greater palindrome
顺序表的实现——静态分配
exception
floyd alfa 2
star print 2
Set Insert Operation
scanf error
typedef char*