Is the runtime error on the sample cases, or when you submit? For what it's worth: I don't know how many bits a "long int" holds. It looks like it has to be at least 32, but maybe it's 64 in VS's compiler and 32 in GCC. I'd use "long long" instead, which is guaranteed to be at least 64 bits.
On Thu, Apr 2, 2020 at 9:31 AM chetas sharma <[email protected]> wrote: > I have written my code in c++14 and it is giving correct output for the > sample test cases in Microsoft Visual studio code 2019 but run time error > in codejam website. > Please help. > > *#include<iostream>* > *#include<cstdio>* > *#include<string>* > *#include<vector>* > *#include<algorithm>* > *#include<math.h>* > *using namespace std;* > *int main()* > *{* > * int t;* > * cin >> t;* > * for (int i = 0;i < t;i++)* > * {* > * long int n, l, d;* > * cin >> n >> l;* > * vector <long int> v;* > * vector <long int> x;* > * vector <long int> z;* > * vector <long int> r;* > * vector <char> w;* > * for (long int k = 2;k <= n;k++)* > * {* > * long int a = 0;* > * for (long int m = 2;m <= sqrt(k);m++)* > * {* > * if (k % m == 0)* > * {* > * ++a;* > * }* > * }* > * if (a == 0)* > * {* > * x.push_back(k);* > * }* > * }* > * d = 0;* > * for (long int j = 0;j < l;j++)* > * {* > * long int c;* > * cin >> c;* > * v.push_back(c);* > * if (j == 0)* > * {* > * for (unsigned long int b = 2;b < x.size();b++)* > * {* > * if (v[0] % x[b] == 0)* > * {* > * z.push_back(x[b]);* > * r.push_back(x[b]);* > * d = v[0] / x[b];* > * break;* > * }* > * }* > * }* > * else* > * {* > * z.push_back(d);* > * r.push_back(d);* > * d = v[j] / d;* > * }* > > * }* > * z.push_back(d);* > * r.push_back(d);* > * sort(r.begin(), r.end());* > * r.erase(unique(r.begin(), r.end()), r.end());* > * for (unsigned long int f = 0;f < z.size();f++)* > * {* > * for (unsigned long int g = 0;g < r.size();g++)* > * {* > * if (z[f] == r[g])* > * {* > * w.push_back(char(g + 64));* > * }* > * }* > * }* > * cout << "Case #" << (i + 1) << ": ";* > * for (unsigned long int h = 0;h < w.size();h++)* > * {* > * cout << w[h];* > * }* > * cout << endl;* > * }* > *}* > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-code/75ad61b0-3ee2-4282-bfb6-e50bdef239d3%40googlegroups.com > <https://groups.google.com/d/msgid/google-code/75ad61b0-3ee2-4282-bfb6-e50bdef239d3%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAHaiWHPf43TgCGLmEJL57hV7hxMUtRETjbY-ovkWgRYLpSP3Dw%40mail.gmail.com.
